require("sqlinfo.inc");
$addate = gmdate("Y-m-d", time());
$errors = "N";
// should we be using MYSQL_CONNECT() here???
$db_connect = @mysql_pconnect($hostname,$username,$password);
if ($db_connect)
{
@mysql_select_db("$dbName");
// query retrieves records matching the site and area passed in
$query = "SELECT a.weighting as weighting, b.bnr_code as bnr_code";
$query = $query.", b.bnr_id as bnr_id, c.background as background ";
$query = $query." FROM banner_sites a, banner b, backgrounds c ";
$query = $query." WHERE a.bnr_id = b.bnr_id ";
$query = $query." AND b.bnr_type = 'banner' ";
$query = $query." AND b.bnr_active = 'Y' ";
$query = $query." AND a.site_code = '".$site."' ";
$query = $query." AND a.site_area = '".$area."' ";
$query = $query." AND a.site_code = c.site_code ";
$query = $query." AND a.site_area = c.site_area ";
$result = MYSQL_QUERY($query);
if (!$result)
{
//print mysql_error();
//return;
$errors = "Y";
}
// populate arrays with the weighting, adcode and banner id so we can process it below
$x = 0;
if ($errors == "N")
{
while ($row = mysql_fetch_assoc($result))
{
$adhtmlcode[$x] = $row[bnr_code];
$adweighting[$x] = $row[weighting];
$bannerid[$x] = $row[bnr_id];
$background = $row[background];
$x += 1;
}
}
}
// handle case where above query returns an error or returns no records
if ($x > 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 "