note 69290 added to function.array-rand
| From: | mark at rugbyweb dot org | Date: | Wed, 30 Aug 2006 08:29:29 +0000 |
| Subject: | note 69290 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116502@lists.php.net to get a copy of this message | ||
I was setting up a rotating add banner and was trying to find a way to go about it using an
auto_increment id from the database, so I wrote this little script:
<?php
require "mysql.php";
global $c;
print "<center>";
$qq=mysql_query("SELECT adID FROM ads WHERE adCLICKS<=adMAX",$c) or die
(mysql_error()."<br>Error, please report this error quoting #QAB");
while($q=mysql_fetch_array($qq))
{
$ad1[$q['adID']]++; //Used an array and inserted the database query results into it.
}
$ad=array_rand($ad1, 1); //Did a random array function and then used it in the query below.
$er=mysql_query("SELECT * FROM ads WHERE adID='$ad'") or die
(mysql_error()."<br>Error, please report this error quoting #QAB3");
if(!mysql_num_rows($er))
{
print "<A href='advertise.php'>Place an ad here!</a>";
exit;
}
$r=mysql_fetch_array($er);
print "<a href='adsout.php?ID={$r['adID']}&BLOCK=1'><img
src='{$r['adAD']}' alt='{$r['adNAME']}'
height='60' width='468'></a>";
?>
----
Server IP: 203.16.234.91
Probable Submitter: 60.226.24.91
----
X-Spam-Status: No, hits=4.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_IMAGE_ONLY_06,HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/69290
Del: integrated -- https://master.php.net/note/delete/69290/integrated
Del: useless -- https://master.php.net/note/delete/69290/useless
Del: bad code -- https://master.php.net/note/delete/69290/bad+code
Del: spam -- https://master.php.net/note/delete/69290/spam
Del: non-english -- https://master.php.net/note/delete/69290/non-english
Del: in docs -- https://master.php.net/note/delete/69290/in+docs
Del: other reasons-- https://master.php.net/note/delete/69290
Reject -- https://master.php.net/note/reject/69290
Search -- https://master.php.net/manage/user-notes.php