RE: [PHP] Banner Ad Script

From: Date: Wed, 12 Jul 2000 10:41:36 +0000
Subject: RE: [PHP] Banner Ad Script
Groups: php.general 
Request: Send a blank email to php-general+get-6105@lists.php.net to get a copy of this message
why not use phpAds? http://www.phpwizard.net/phpAds Sincerely berber Visit http://www.weberdev.com Today!!! To see where PHP might take you tomorrow. -----Original Message----- From: John Coggeshall [mailto:someone@internetaddress.com] Sent: Tuesday, July 11, 2000 8:59 PM To: Andrew; php-general@lists.php.net Subject: RE: [PHP] Banner Ad Script I appologize, but I'm a bit in a rush so I didn't have a chance to look at your code... however... If you set the weight to go from 1-100 (1 being lowest chance) then you would loop through the rows one by one, except every time you cycle through the loop, increase the chances that the loop will fail the next time around. When you have reached that point, or at the end of the rows, you exit the loop and use the last result you got as the banner you will use... therefore.. Chance of getting the first banner 1:10 odds Chance of getting second banner 1:100 odds Third 1:1000 odds Fourth 1:10000 etc. etc. etc. (note, you don't necessarily have to increase the chance by a factor of 10, you could use a decimal or a small integer as well - you get the idea I hope) John -----Original Message----- From: Andrew [mailto:fisherres@msn.com] Sent: Tuesday, July 11, 2000 11:19 PM To: php-general@lists.php.net Subject: Re: [PHP] Banner Ad Script Thanks for replying, but I'm afraid this isn't going to work without hanging every now and then. Do you have any suggestions on how I can select random banner ad(s) based on weight w/ one being the lowest? Currently, I'm using the following algorithm which works great if you only have one banner ad: What I have done in the past is place each banner into an array n number of times, where n is the banner weight. This way banners with higher weight appear in the array more times than banners with a lower weight, and thus have a higher chance of being selected. Note that when I have done this, I only store the index to the banner (unique ID) within the array. Andrew digi-FX ------------------------------- http://www.digi-FX.net ----- Original Message ----- From: Andrew <fisherres@msn.com> To: <php-general@lists.php.net> Sent: Tuesday, July 11, 2000 4:50 PM Subject: [PHP] Banner Ad Script > Hello, > > I'm working on a banner ad rotation script in PHP. The following is the > code I came up with; however, at times it exceeds the maximum execution time > and other times it works fairly fast. Any ideas... > > Code Sample: > <?php > class digiAds { > var $ad; > > function digiAds ($max = 4) { > global $mysql_host, $mysql_user, $mysql_pass, $mysql_db, $digiAds; > mysql_connect ($mysql_host, $mysql_user, $mysql_pass); > mysql_select_db ($mysql_db); > $result = mysql_query ("SELECT id, weight FROM digiAdst WHERE > enabled='yes'"); > while ($row = mysql_fetch_array ($result)) { > for ($i = 0; $i < $row["weight"]; $i++) > $ids[] = $row["id"]; > } > mysql_free_result ($result); > > $i = 1; > > // THE SCRIPT CHOKES HERE > while ($i != $max) { > mt_srand ((double) microtime () * 1000000); > $picked_ad = mt_rand (1, count ($ids)); > for ($i = 0; $i < count ($used_ads); $i++) { > if ($ids[$picked_ad] == $used_ads[$i]) > $used = true; > } > if (!$used) > $used = false; > if ($used == false) { > mysql_query ("UPDATE digiAdst SET views=views+1 WHERE > id='$ids[$picked_ad]'"); > $result = mysql_query ("SELECT img, width, height FROM > digiAdst WHERE id='$ids[$picked_ad]'"); > $row = mysql_fetch_array ($result); > mysql_free_result ($result); > $this->ad[] .= "<a href=/digi-ads/clicks.php?id=" . > $ids[$picked_ad] . " target=_blank><img src=" . $digiAds["path"] . > $row["img"] . " width=" . $row["width"] . " height=" . > $row["height"] . " > border=0></a>"; > $used_ads[] = $ids[$picked_ad]; > $i++; > } > } > mysql_close (); > } > } > ?> > > > > BTW, I call the script as so: > Code Sample: > <table width=500 border=0 cellspacing=2 cellpadding=2 align=center> > <tr> > <?php $buttons = new digiAds (4); ?> > <td width=25% align=center><?php echo $buttons->ad[0]; ?></td> > <td width=25% align=center><?php echo $buttons->ad[1]; ?></td> > <td width=25% align=center><?php echo $buttons->ad[2]; ?></td> > <td width=25% align=center><?php echo $buttons->ad[3]; ?></td> > </tr> > </table> > > Andrew > digi-FX > ------------------------------- > http://www.digi-FX.net > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#6105) next »