SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everyone,

    I'm trying to make a random quote script using php.
    i have a mysql table 'quotes' with 3 columns, ID, quotes, author.

    what i want to do is create a randomize number from 1 to the number of quotes available in the table base on the ID. Then display the quote base on that.

    Any help would be greatly appreciated!


    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the only problem is that if you are using an auto-incrementing field for your ID there may be a chance that you could select an ID that has been deleted, but anyways here is a script that will suit your needs. I also use PHPLIB for my db stuff, so if this doesn't make sense let me know and I will put into regular php.

    include("./db.inc");
    $db = new DB;
    $db->query("SELECT count(ID) as count from listings");
    $db->next_record();
    $count = $db->f(count);
    srand((double)microtime()*1000000);
    $rand = rand (0,($count));
    $db->query("SELECT * FROM listings WHERE ID = '$rand'");
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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