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

Thread: Display Random

  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Display Random

    Here is my code, i need it to display 1 entry from the database randomly? And ideas. As you can tell im a newbie

    PHP Code:
      <?php
            $sql 
    "SELECT * FROM banner";
                
    $result mysql_query($sql$conn) or die(mysql_error());
                    while (
    $newArray mysql_fetch_array($result)) {
                        
    $banner_id $newArray['banner_id'];
                        
    $banner_dir $newArray['banner_dir'];
                        
    $banner_bussiness $newArray['banner_bussiness'];
                        
    $banner_website    $newArray['banner_website'];
                echo 
    "<a href='$banner_website'><img src='banner/$banner_dir' alt='$banner_bussiness' border='0' height='60px' width='468px'></a>                ";
            }
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    SELECT * FROM foo ORDER BY RAND() LIMIT 1
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

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