I found this small scrpt on the net that is used for avertising banners and is supposed to use a weight of 1-10 to show banners more frequent with a higher weight, below is the code, I don't understand the weight part enough, can someone that might understand it tell me if the weight really works to show it more often? Maybe you can explain how the weight works in this script? Appreciate any help
DB Table
-- Table structure for table `advertisements`
--
CREATE TABLE IF NOT EXISTS `advertisements` (
`id` int(10) NOT NULL auto_increment,
`code` text NOT NULL,
`url` text NOT NULL,
`weight` int(10) NOT NULL default '0',
`clicks` int(10) NOT NULL default '0',
`views` int(10) NOT NULL default '0',
`email` text NOT NULL,
`owner_name` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
<?php
require_once "../config/functions.inc.php";
// -- Start Banner Array --
$sql = "select * from advertisements order by id asc";
$results = executeQuery($sql);
//$prodlist = array ();
while ($row = mysql_fetch_assoc($results)){
for ($x=1;$x <= $row[weight];$x++){
$prodlist[] = $row[id];
}
}
srand ((double) microtime() * 1000000);
$magicnumb = rand(0, count($prodlist)-1);
$magicnum = $prodlist[$magicnumb];
//get banner
$sql2 = "select * from advertisements where id = $magicnum";
$results2 = executeQuery($sql2);
while ($row2 = mysql_fetch_assoc($results2)){
$add = $row2[views] + 1;
//update views
$sql3 = "update advertisements set views = $add where id = $row2[id]";
executeQuery($sql3);
// show banner
print "<A HREF=\"banner/redirect.php?id=$magicnum\" TARGET=\"_blank\">";
print $row2['code'];
}
?>