Page 1 of 1

Rotating banner with hitcounter?!?

Posted: Wed Jun 11, 2008 3:09 am
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 :-)

Re: Rotating banner with hitcounter?!?

Posted: Wed Jun 11, 2008 5:15 am
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?

Re: Rotating banner with hitcounter?!?

Posted: Wed Jun 11, 2008 5:23 am
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'");