Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    confused about using rand()

    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.
    God helps those who help others.

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    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 Code:
    <?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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •