Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to find the most popular ID

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to find the most popular ID

Postby inoob » Wed Apr 10, 2013 6:27 am

Ive been thinking for the past hour on how to find the most popular ID in my mysql database. Is this only possible through visitor counting or is there another way to do this but accurately? Basically when a user visitor any ID page. for example .php?id=1 or .php?id=2, I just want to know which one was visited the most so that I can display the 5 popular ID's visited.

I already set up a php code where it displays 5 supposed 'popular' items in the website, but it's really showing the first 5 records instead.

A good example would be http://www.nytimes.com

Any input would be helpful :)
Thanks.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: How to find the most popular ID

Postby johnj » Wed Apr 10, 2013 6:54 am

Keeping a count in the database, looks like is the ideal way.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: How to find the most popular ID

Postby inoob » Wed Apr 10, 2013 9:55 am

Thanks for the reply. Here is what I have so far:

Code: Select all
<?php
$id=(int) $_GET['id'];
if(!isset($_SESSION['$id'])){
$_SESSION["'$id'"]=$id;
$sql = "UPDATE table SET fldVisits = fldVisits + 1 WHERE fldID ='$id' LIMIT 1";
mysql_query($sql) or die(mysql_error());
echo 'fldVisits'
?>


fldID is the ID of the pages. Ex. .php?id=1, .php?id=2 etc..
fldVisits is where the number adds +1 for each visit by sessions.

I am getting a syntax error. I suppose im writing the wrong quotes. What am I doing wrong here?
Last edited by inoob on Wed Apr 10, 2013 5:01 pm, edited 1 time in total.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: How to find the most popular ID

Postby seandisanti » Wed Apr 10, 2013 2:30 pm

actually, making use of free google analytics is the best way. It can be used to track traffic, plus how many people landed or exited each page, etc. You'd be surprised at just how much you can actually see with google analytics. Lynda.com has a great course on it that even shows how to successfully use google analytics to track offline advertising campaigns. It's good, it's easy, and it's free, and you can cut the data up any way you want, including seeing the popularity of specific browsers, or operating systems among your visitors.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to find the most popular ID

Postby inoob » Wed Apr 10, 2013 5:00 pm

I fixed up the code. Thanks guys. Thanks for the idea of using Google Analytics. I have that on the side ready. Your correct. I just need a little feature like displaying the most popular ID similar to http://www.nytimes.com and I got it working. I just had the quotes wrong.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.