Jonsta Posted March 2, 2009 Share Posted March 2, 2009 Hi i am starting a site and would like to have a most popular pages list on everypage visited which is why i cannot do it on HTML. I would like it to display the top 20 pages (either by hits, preferably on a time basis), or user rating (stars). I have listed the things i think i need the php code to do. The things i think it needs to do are: [*]gather the amount of hits/star rating from every page [*]sort the values into the numerical order where the highest is top [*]list the first 20. If you could help me find a way t do this would be extremely greatful so please even if it may only help abit or if it is stating the obvious(i really am a noob to php), i would really appreciate them. Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/ Share on other sites More sharing options...
br0ken Posted March 2, 2009 Share Posted March 2, 2009 First you'll need a database. You'll need one table for your pages, another for ratings and maybe another for users. Each time a user rates a page, you'll need to update your database to show this. You'll then need a PHP page that requests the pages from the database in the order of most popular or highest rating. You can then use PHP to list these in some way. Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-774963 Share on other sites More sharing options...
Jonsta Posted March 3, 2009 Author Share Posted March 3, 2009 thanks this post has been extremely helpful a few questions though. couldnt i just use fields e.g. a table called 'pages' with the fields: page_id, page_name, page_hits, page_rating. and also how do i make the sql get updated by user activity? any suggestions of a tutorial. thanks Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-775761 Share on other sites More sharing options...
br0ken Posted March 3, 2009 Share Posted March 3, 2009 While I wouldn't design my database like that, you certainly could do. To measure activity have a function like the one below on each page you want to measure. function recordHit($page) { // Connect to db code here // Clean database input $page = mysql_real_escape_string($page); // Update the database $res = @mysql_query("UPDATE tblPages SET hits = (hits + 1) WHERE name = '$page'"); // Close DB code here return ($res); } This code is a simplified version of what you want and will need to be expanded on but it should get you going. Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-775793 Share on other sites More sharing options...
Jonsta Posted March 4, 2009 Author Share Posted March 4, 2009 Thanks, i think ill try that this has been realy helpful however i do not know SQL if you or anyone knows of anyone tutorials please post it in here. thanks Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-776569 Share on other sites More sharing options...
br0ken Posted March 4, 2009 Share Posted March 4, 2009 There are many out there but after a quick Google search this one seem like the best: http://www.w3schools.com/PHP/php_mysql_intro.asp Go through each page clicking 'Next' at the bottom to progress to the next page. Also, the PHP MySQL section will provide an indepth explanation of all MySQL functions available in PHP. http://php.net/mysql Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-776586 Share on other sites More sharing options...
Jonsta Posted March 5, 2009 Author Share Posted March 5, 2009 thanks alot for all your help br0ken, without it i would still be stuck as it seems no one else likes answering my questions. anyway im going to select this topic as solved. if anyone wants to post i could always use some good tutorials. thatnks again. Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-777529 Share on other sites More sharing options...
br0ken Posted March 6, 2009 Share Posted March 6, 2009 That's not a problem. This board has helped me in a lot in the past so the least I can do is help others. I've tried to find more good MySQL tutorials but couldn't find that many. Here are a few I've found though: http://www.webmonkey.com/tutorial/PHP_and_MySQL_Tutorial_-_Lesson_3 http://www.devshed.com/c/a/MySQL/Beginning-MySQL-Tutorial/3/ Also, there is a program called phpMyAdmin which allows the user to create and edit tables using a GUI. While in the long term it's much better to actually learn SQL, using phpMyAdmin provides a quick and easy way to get a database up and running. Here is the link if you want to check it out: http://www.phpmyadmin.net/home_page/index.php Link to comment https://forums.phpfreaks.com/topic/147597-solved-gathering-and-displaying-lists/#findComment-778106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.