Jump to content

[SOLVED] gathering and displaying lists


Jonsta

Recommended Posts

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

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.

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

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.

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

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.