#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Sydney, NSW, Australia
    Posts
    40
    Rep Power
    14
    Hi,

    I am trying to select a randon entry from mysql. Anyway - My version of mysql doesn't have the built in rand() function, so I am using PHP's. Anyway - I wrote the following function...

    function displayguide(){
    $rand = rand(10,202000);
    connect();
    $query = "SELECT *, $rand as random FROM guide_rotater ORDER BY random LIMIT 1";
    $result = mysql_query($query);
    $this = mysql_fetch_object($result);
    print "<b>$this->title</b><p>$this->description<p><a href="$this->url"><b>Read the guide</b></a>";
    }

    Anyway - it works, the only problem is that it uses the same $rand number for all of them so it isn't random

    I can't think of a way to do this using php's rand function. Can someone please help - I am sure its something simple, but I donno what the hell it is.

    ------------------
    Michael Bray
    http://www.webhostarea.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    You need to call srand() before you call rand():
    http://www.php.net/manual/function.srand.php

Similar Threads

  1. MYSQL, php, random generate
    By LeBoOo in forum PHP Development
    Replies: 2
    Last Post: September 30th, 2004, 01:47 PM
  2. Check MySQL Version thru PHP
    By wolftrap1 in forum PHP Development
    Replies: 2
    Last Post: February 11th, 2004, 08:51 PM
  3. Replies: 0
    Last Post: February 10th, 2004, 11:44 PM
  4. PHP 5 (MYSQL vs. SQLite)
    By ignition in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 12:13 PM
  5. PHP Reconfig with mysql...
    By Legendary Fox in forum PHP Development
    Replies: 3
    Last Post: January 22nd, 2004, 11:46 PM

IMN logo majestic logo threadwatch logo seochat tools logo