kirbyweb Posted November 26, 2009 Report Share Posted November 26, 2009 OK my flash game website is about done.kingdomsarcade.byethost5.comanyways, I have one question.On the left side of the home page there is the most popular games, how would I make it so that the most visited game would show up there? Link to comment Share on other sites More sharing options...
Synook Posted November 27, 2009 Report Share Posted November 27, 2009 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 More sharing options...
kirbyweb Posted November 27, 2009 Author Report Share Posted November 27, 2009 How would I do that? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 27, 2009 Author Report Share Posted November 27, 2009 it would be hard to make every single page, in my db wouldn't it? Link to comment Share on other sites More sharing options...
norNerd Posted November 27, 2009 Report Share Posted November 27, 2009 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 More sharing options...
kirbyweb Posted November 27, 2009 Author Report Share Posted November 27, 2009 It would be hard to add all the pages in the db though wouldnt it? Link to comment Share on other sites More sharing options...
norNerd Posted November 27, 2009 Report Share Posted November 27, 2009 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 More sharing options...
kirbyweb Posted November 27, 2009 Author Report Share Posted November 27, 2009 hmm am I suppose to make a new page? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 28, 2009 Author Report Share Posted November 28, 2009 OK I did it, now how do I make it so if the page was visited it updates clicks +1?I do not want to make it so if the link was clicked, just if the page was viewed. Link to comment Share on other sites More sharing options...
Synook Posted November 28, 2009 Report Share Posted November 28, 2009 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 More sharing options...
kirbyweb Posted November 28, 2009 Author Report Share Posted November 28, 2009 How and where would I assign it? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 28, 2009 Author Report Share Posted November 28, 2009 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 More sharing options...
norNerd Posted November 28, 2009 Report Share Posted November 28, 2009 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 More sharing options...
norNerd Posted November 28, 2009 Report Share Posted November 28, 2009 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 More sharing options...
justsomeguy Posted November 28, 2009 Report Share Posted November 28, 2009 You can also just store the entire filename of the current script, you can get that from several places in the $_SERVER array:http://www.php.net/manual/en/reserved.variables.server.php Link to comment Share on other sites More sharing options...
kirbyweb Posted November 29, 2009 Author Report Share Posted November 29, 2009 My question is, how does the code tell what the page is?My page is kingdomsarcade.byethost5.com/2d_Knockout_gameplay.php but in the db I just added 2d_Knockout_gameplay.phpso would it still get the url? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 29, 2009 Author Report Share Posted November 29, 2009 Like I have an include php file, its included on all the files, so can I just do something there? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 29, 2009 Author Report Share Posted November 29, 2009 OK I did it, now how do I make the top 4 clicks pop up in the table? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2009 Report Share Posted November 29, 2009 When you send the SELECT query to the database to get the records from that table, you can order descending by the number of clicks, and then use LIMIT to only return 4 records, e.g.:SELECT * FROM page_table ORDER BY clicks DESC LIMIT 4 Link to comment Share on other sites More sharing options...
kirbyweb Posted November 29, 2009 Author Report Share Posted November 29, 2009 (edited) ok I echo it out with $get_clicks['page'] and it shows up the highest one, how do I make it show the 4 highest? Edited November 29, 2009 by kirbyweb Link to comment Share on other sites More sharing options...
kirbyweb Posted November 30, 2009 Author Report Share Posted November 30, 2009 Is anyone going to help? Link to comment Share on other sites More sharing options...
Synook Posted November 30, 2009 Report Share Posted November 30, 2009 Well, your query is selecting four records, you need to loop through them all. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 30, 2009 Author Report Share Posted November 30, 2009 How? Link to comment Share on other sites More sharing options...
Synook Posted November 30, 2009 Report Share Posted November 30, 2009 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 More sharing options...
kirbyweb Posted November 30, 2009 Author Report Share Posted November 30, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now