Jump to content

Website About Done


kirbyweb
 Share

Recommended Posts

Are you currently tracking the most visited games? You could have a small query on each game's page that updates a database table entry for that game, and then query that table on the front page.

Link to comment
Share on other sites

You can use:

<?php mysql_query("UPDATE `your_mysql_database`.`your_page_table` SET clicks=clicks+'1' pageId='".$_GET['thePageID_that_the_user_is_on']."'");//If this dont work, try clicks=cliks'+1' ?>

Add table your_page_table in your mysql db,and have an id for every page you haveand clicks for every click that comes.You can add this to your mysql database by using:

$mysql_pass = "your_pass";$mysql_user = "your_user";$mysql_host = "your_host";$mysql_data = "your_database";// Now connect to mysql servermysql_connect("$mysql_host","$mysql_user","$mysql_pass") or die("Error: <br />" .mysql_error());//Then connect to mysql_databasemysql_select_db("$mysql_data") or die("Error: <br />" .mysql_error()); // Now we set up the create table query$insert = "CREATE TABLE `$mysql_data`.`your_page_table` (`id` int(225) NOT NULL AUTO_INCREMENT PRIMARY KEY,`clicks` varchar(225) NOT NULL) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci";//Then check if someone clicked the button "Create Table Clicks"if(isset($_POST['create_table_clicks'])){//If someone clicks, then run mysql_query on the create table querymysql_query("$insert") or die("Error: <br />" .mysql_error());}?><html><head><title>Create Table - Clicks</title></head><body><form name="create_form" method="post" action=""><input type="submit" name="create_table_clicks" value="Create Table Clicks" /></form></body></html>

Hope that helps :)Kris

Link to comment
Share on other sites

Code:

//First you will have to insert page row into your mysql_database//Add with following data: `page` varchar(32) NOT NULL,//Add this to create_page.php if(isset($_POST['add_page'])){$page = $_POST['page'];mysql_query("INSERT INTO `$mysql_data`.`your_page_table` (`id`,`page`,`clicks`)VALUES('','$page','0')") or die("Error: <br />" .mysql_error());}

Add this to html code in create_page.php

<form name="create_page" method="post" action=""><input type="text" name="page" id="page" /><input type="submit" name="add_page" value="Add page to database" /></form>

Hope it helps, just write name into textfield "page" and click add page to database button to add a page :)Kris

Link to comment
Share on other sites

You can automatically check whether a certain game is in the counter table, and if not add it. To add, one, just assign the `field` + 1.

Link to comment
Share on other sites

Like I did it, but I want to know how to make it so, if you are on that page it updates that page, not just a random one in the db table.So the names I have in the db are the names I have on the website, example (2d_Knockout_gameplay.php) how do I make it so if your on that page then it will update that certain page in the db.

Link to comment
Share on other sites

you can have this one:

mysql_query("UPDATE `$mysql_data`.`page_table` WHERE pagename='$pagename'") or die("Error: " .mysql_error());

on each site.You can either use get function in your links to the game like this:yourdomain.com/pagename.php?pagename=pagenamethen run the query like this

$pagename = $_GET['pagename'];mysql_query("UPDATE `$mysql_data`.`page_table` WHERE pagename='$pagename'") or die("Error: " .mysql_error());

or you can set a variable like this on each page

$pagename="pagename";mysql_query("UPDATE `$mysql_data`.`page_table` WHERE pagename='$pagename'") or die("Error: " .mysql_error());

Any questions? :)Kris

Link to comment
Share on other sites

Whoops forgot one important thing!!You need to add this SET clicks=clicks'+1' after `$mysql_data`.`page_tabe`So it looks like this

mysql_query("UPDATE `$mysql_data`.`page_table` SET clicks=clicks+'1' WHERE pagename='$pagename'") or die("Error: " .mysql_error());

Kris

Link to comment
Share on other sites

Something like:

$result = mysql_query("SELECT * FROM page_table ORDER BY clicks DESC LIMIT 4");while ($row = mysql_fetch_assoc($result)) {echo $row["page"];}

Or whatever, depending on your code.http://www.w3schools.com/php/php_mysql_select.asp

Link to comment
Share on other sites

OK, now in my table it has / and gameplay.php / in the beginning and gameplay.php at the end, I had to use / in the db because I was using SERVER URI or what ever, so how would I make the / and gameplay.php not show?

<?php$get_clicks = mysql_query("SELECT * FROM `____` ORDER BY clicks DESC LIMIT 5") or die(mysql_error());while ($rows = mysql_fetch_array($get_clicks)) {extract($rows);$rows['n_sets_per_page'];<span style='color: white;'><?phpecho $rows['page'];} ?>

So how would I add <br />'s after each page and take the / and gameplay.php out when I echo it?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...