Page 1 of 1

random but equal to all

Posted: Mon May 09, 2005 5:05 am
by nikhil.deshmukh
hello friend is it possible and how to do that


i have 6 banners in the mysql now i want to show the banners randoms which i have done it

but now what i want is the banners should show in equal numbers

if a banner is shown banner1.jpg is displayed 10 times and another banner2.jpg is shown only 8 times then the banner2,.jpg will complete the 10 figure first is it possible i am pasting some of the code...

Code: Select all

<?php
require "connection.php";
echo "shree swami samartha<br>";

//echo "<a href=http://google.com><img src=468x60.gif width=468 height=60 border=0></a>";

$result = mysql_query("SELECT * FROM banner_data order by rand() limit 1");
while($row=mysql_fetch_array( $result ))
{
$url=$row['url'];
$img_src=$row['img_src'];
$img_alt=$row['alt'];
$banner_id=$row['banner_id'];
$hits=$row['hits'];

//echo "<b>".$banner_id.$url.$hits."<b>";
echo "<a href=click.php?&i=".$banner_id."&jump_url=".$url."><img src=".$img_src." border=0></a>";

$nhits=$hits + 1 ;

echo $nhits;

mysql_query("UPDATE banner_data SET hits='$nhits' WHERE banner_id='$banner_id'");

//echo "<BR>Record $ud_id <-- Updated<BR><BR>";



}


?>
d11wtq | Please read the sticky about posting code in the forums ;-)

Posted: Mon May 09, 2005 5:13 am
by onion2k
Change the query where you get a banner from the database to:

"SELECT * FROM banner_data order by hits asc, rand() limit 1"

That should get a random record where the hits equal to the lowest value.

Posted: Mon May 09, 2005 5:38 am
by nikhil.deshmukh
but if the banner1.jpg having 5 hits what if i have submited banner3.jpg which have 0 hits

it is not comming where in banner1 goes 15 times where banner3.jpg only 6 times

any solution on that

Posted: Mon May 09, 2005 5:47 am
by Chris Corbyn
:arrow: Moved to PHP Code

Posted: Mon May 09, 2005 5:49 am
by onion2k
Did you try the code I posted?

Posted: Mon May 09, 2005 7:58 am
by nikhil.deshmukh
yes i tried


ur r right it
gives me what i want
.... thanks a lot