IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

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


XtremeGamer99
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 17
Joined: 16-September 04
Member No.: 1,132



Post #1 post Sep 21 2004, 07:32 PM
I want a PHP code to display the most popular clicks/links on certain pages.

Can anyone help?
Go to the top of the page
+Quote Post
virrey
no avatar
Newbie
*
Group: Members
Posts: 9
Joined: 8-October 04
Member No.: 1,524



Post #2 post Oct 8 2004, 07:16 PM
you need to create a counter database for each url
in your site
increment each time (using php)
then create the stats
Go to the top of the page
+Quote Post
whatknows
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 10
Joined: 10-October 04
Member No.: 1,618



Post #3 post Oct 10 2004, 08:08 AM
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.
Go to the top of the page
+Quote Post
jordanliuhao
no avatar
Newbie [Level 2]
**
Group: Members
Posts: 32
Joined: 30-January 05
Member No.: 3,494



Post #4 post Feb 1 2005, 06:11 AM
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.


QUOTE(XtremeGamer99 @ Sep 21 2004, 02:32 PM)
I want a PHP code to display the most popular clicks/links on certain pages.

Can anyone help?
[right][snapback]13863[/snapback][/right]
Go to the top of the page
+Quote Post
FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #5 post Feb 2 2005, 10:21 PM
QUOTE
you need to create a counter database for each url
in 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:

CODE
<?
mysql_connect("localhost","user","password");
mysql_select_db("databasename");

if(!$ref) // if area hadn't be specified
die("You didn't specified an area!");

$ref = stripslashes($ref); // security reason

mysql_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.
Go to the top of the page
+Quote Post
FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #6 post Feb 2 2005, 10:31 PM
i've forgot... just completing.
to display the most popular in tables, just write this code:

show.php

CODE

<?
// 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 blah

while($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! \_
Go to the top of the page
+Quote Post
alexwhin
no avatar
Member [Level 1]
****
Group: Members
Posts: 74
Joined: 9-December 04
From: wales (bridgend)
Member No.: 2,631



Post #7 post Feb 9 2005, 10:48 AM
FaLgoR thanx for the tip man that will be very useful
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   3 -Sky- 664 12th June 2009 - 08:48 PM
Last post by: -Sky-
No New Posts 7 odomike 19,029 30th April 2008 - 02:44 PM
Last post by: FeedBacker
No new   97 Xenon 47,384 29th October 2009 - 04:25 PM
Last post by: magiccode9
No New Posts   11 bttfpromo 11,547 14th September 2004 - 08:55 PM
Last post by: Magic-Node
No new   25 gijoe18 24,501 20th February 2009 - 06:55 PM
Last post by: MALISH_
No New Posts   1 BCD 180 3rd September 2009 - 09:28 PM
Last post by: truefusion
No New Posts   5 Tetraca 1,252 15th July 2006 - 11:06 PM
Last post by: Plenoptic
No New Posts   4 icss21 3,027 7th March 2009 - 09:45 PM
Last post by: andreip
No New Posts   3 jglw22 891 26th May 2008 - 02:10 PM
Last post by: Framp
No new 18 FirefoxRocks 2,106 2nd January 2009 - 08:07 AM
Last post by: triplebtalk
No New Posts   4 Forbidden 7,570 28th March 2008 - 07:37 PM
Last post by: saran
No New Posts   6 sargilla 6,812 4th November 2004 - 02:54 PM
Last post by: Lyon
No New Posts   4 icss21 950 22nd July 2006 - 02:24 PM
Last post by: JField
No New Posts   0 Lyon 3,575 3rd November 2004 - 07:27 PM
Last post by: Lyon
No New Posts 0 Dodger 3,267 3rd November 2004 - 08:34 PM
Last post by: Dodger


 



RSS Open Discussion Time is now: 22nd November 2009 - 10:03 AM

Web Hosting Powered by ComputingHost.com.