Rotating banner with hitcounter?!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Rotating banner with hitcounter?!?

Post by jmansa »

I have made this rotating bannerscript wich works fine, but I am not able to collect hitstats. Where do I go wrong?

Code: Select all

$num_displayed = 1 ;
 
$result = mysql_query ("SELECT * FROM sponsor WHERE uid=".$uid." AND sponsor_b=1 ORDER BY RAND() LIMIT $num_displayed"); 
 
while ($sponsor_b = mysql_fetch_array($result)) 
 
{
$sponsor_b_id = $sponsor_b['sponsor_id'];
$sponsor_b_image = $sponsor_b['image'];
$sponsor_b_url = $sponsor_b['url'];
}
 
function dbIncClks($sponsor_b_id) { 
 
$query="SELECT hits FROM sponsor WHERE(sponsor_id='$sponsor_b_id')";
 
    If(num_rows() == 0) { 
        return false; 
    } 
 
query("UPDATE sponsor SET hits=".(f('hits')+1)." WHERE(sponsor_id='$sponsor_b_id')"); 
 
}
I can't see the error... Please help :-)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Rotating banner with hitcounter?!?

Post by superdezign »

Assuming that somewhere between there, you actually call the function, then the problem is in your function.

What is f('hits')?
What is the f() function and what does it do?
Where is the query() function defined?
And how come you haven't run the query you created, let alone use any data from its results?
What is actually going wrong?
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Re: Rotating banner with hitcounter?!?

Post by jmansa »

Sorry... I solved it by doing this:

Code: Select all

$q = mysql_query("SELECT hits FROM sponsor WHERE sponsor_id='$sponsor_b_id'");
 
if (!$q)    
  return false; 
 
mysql_query("UPDATE sponsor SET hits=hits+1 WHERE sponsor_id='$sponsor_b_id'");
Post Reply