Re: Banner Ad Script

From: Date: Wed, 12 Jul 2000 16:37:05 +0000
Subject: Re: Banner Ad Script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6181@lists.php.net to get a copy of this message
I think I solved my problem which was in my algorithm, but I need your help... 1. I have an array $array = array (1,2,3,3,3,4,5,6,7,8,9,9); 2. The variable $picked has the value 2. 3. If I print the value of $array[$picked] I see the number three. 4. Well instead of printing the number three I want to remove all instances of 3 from the array. So, my array should look like $array = array (1,2,4,5,6,7,8,9,9); Basically, whatever the value of $array[picked] is, I want to remove all instances of that value from 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 > >

« previous php.general (#6181) next »