0) { // get total of all weightings $i = 0; $adtotal = 0; while ($i < $x) { $adtotal += $adweighting[$i]; $i += 1; } // create a random number that falls within the weighting total $navrand = mt_rand(1,$adtotal); //print "
navrand=".$navrand; // using the random number, increase the accumulator until the random ad is hit // when the accumulator is bigger than the random number, the ad is displayed and the code exits // after updating the stats $i = 0; $adaccum = 0; while ($i < $x) { $adaccum += $adweighting[$i]; if ($navrand <= $adaccum) { //new burst code needs a randomid so we will generate that here //and replace below if necessary $hgrandid = mt_rand(100000,999999); print "
\n"; $adcodeoutput = str_replace("RANDOMID",$hgrandid,$adhtmlcode[$i]); print $adcodeoutput; //print $adhtmlcode[$i]; print "\n"; $bnrid = $bannerid[$i]; // using seperate records in the stats table for imps vs count // should help a little bit on the record locking issue $query = "UPDATE stats SET sta_count=sta_count+1 WHERE bnr_id=$bnrid AND sta_date='$addate' AND sta_type = 'imp'"; $result = mysql_query($query); if (!$result) { print mysql_error(); return; } // if update affects 0 rows, that means there are no stats for today so far... so create a new record if (mysql_affected_rows() == 0) { $query = "INSERT INTO stats (bnr_id, sta_type, sta_date, sta_count) VALUES ($bnrid,'imp','$addate',1)"; $result = mysql_query($query); if (!$result) { print mysql_error(); return; } } return; } $i += 1; } } else // this else occurs if x=0 - which means there was an error in the query or no records were returned // this ensures an ad is served even if the above fails // this really should never be executed but it's here as a failsafe { if ($area == "content") { // if area = content, we are safe to use the fastclick code print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; return; } else { // if we can't be sure the area is content, we have to use the Burst Code print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "\n"; return; } } ?>