Jump to content
xisto Community
Sign in to follow this  
XtremeGamer99

I Want A Php Code To Display The Most Popular...

Recommended Posts

virrey is right on. Think about added code to the top of each of the pages you wish to track. The query could insert $PHP_SELF into a page column, giving you a row for each page load.Alternately you could set up another field as "hits" and then do a query to see if a row for that page is already in the database. If it is, use UPDATE, if not, INSERT.Eventually when MySQL 4.1 goes from Gamma release to General, you will be able to use "INSERT... ON DUPLICATE KEY SET..." which will let the database decide whether to update or insert.

Share this post


Link to post
Share on other sites

You need a counter to track the clicks.

 

There are 3 ways to do this.

 

One is shared memory. Reference http://ca.php.net/manual/en/function.shm-attach.php

 

One is files. You track the count in your file. Be care of the synchronize problem.

the process should be:

 

<?

fopen()

flock(LOCK_EX)

fread()

count++

fwrite()

flock(LOCK_UN)

fclose()

 

?>

 

One is database. You save the click to database.

 

 

I want a PHP code to display the most popular clicks/links on certain pages.

 

Can anyone help?

13863[/snapback]

Share this post


Link to post
Share on other sites

you need to create a counter database for each urlin your site
increment each time (using php)
then create the stats

or, in the full code, it will be just like this:

create an database table whit the following rows:
-id
-name
-clicks

and an page called link.php:

<?mysql_connect("localhost","user","password");mysql_select_db("databasename");if(!$ref) // if area hadn't be specifieddie("You didn't specified an area!");$ref = stripslashes($ref); // security reasonmysql_query("UPDATE table SET clicks=(clicks+1) WHERE name='$ref';");include("$ref.htm"); // include the real page?>

Now, you just need to fill the database with your areas and change all links. If the link was games.htm, it will be link.php?ref=games
That's all :] if the script doesn't run, post again and I'll fix the problems.

Share this post


Link to post
Share on other sites

i've forgot... just completing.
to display the most popular in tables, just write this code:

show.php

<?// don't forget to connect with database?><table border="0"><tr><td>Area</td><td>Clicks</td></tr><?$query = mysql_query("SELECT * FROM table ODER BY clicks LIMIT 5;"); // if you want to show 10 most popular, change 5 for 10, or if you want the 15 more, change for 15... blah blah blahwhile($most = mysql_fetch_array($query)){?><tr><td><?=$most[name]?></td><td><?=$most[clicks]?></td></tr><?}?></table>

that's all! You know, if this script doesn't run, post here and I'll fix it. And don't forget to conect whit the database in the top of this page. If u don't know how, just look at my other post. There is an example. I hope I've helped you! \_

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.