random but equal to all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nikhil.deshmukh
Forum Newbie
Posts: 7
Joined: Sun May 08, 2005 11:13 pm

random but equal to all

Post 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 ;-)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
nikhil.deshmukh
Forum Newbie
Posts: 7
Joined: Sun May 08, 2005 11:13 pm

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:arrow: Moved to PHP Code
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Did you try the code I posted?
nikhil.deshmukh
Forum Newbie
Posts: 7
Joined: Sun May 08, 2005 11:13 pm

Post by nikhil.deshmukh »

yes i tried


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