...

View Full Version : confused about using rand()



amir
10-27-2005, 05:36 AM
hi all
i have a database table "user_ads" and i m getting values from it like adsID, adsLink, adsDescription. i may have more than 10 records in my table but i have to display only three records at one time.
i want whenever page is reloaded, new links with their description should be displayed. i m already doing it somewhere using rand() and it works fine but only for displaying one value. now my problem is that i have to display three values.

thanx in advance.
Regards,
Aamir.

Serex
10-27-2005, 07:01 AM
Just thrown something together quickly before work, havent fully tested it although cant see anything overly wrong syntax wise. You will need to adjust for your naming convention, or manually enter the names into the array. good luck



<?php
srand(time());
for ($j = 0; $j <= 10; $j++)
{
$images[$j] = "image_" . $j . ".gif";
}

for ($i=0; $i < 3; $i++)
{
$random = (rand()%10);
$display[$i] = $images[$random];
}

echo $display[0] . "<br />";
echo $display[1] . "<br />";
echo $display[2];
?>


if you need any help just ask



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum