Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6

Thread: Random ID

  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Hello, I want to build a PHP Script that will read a random article from my DB

    mySQL Structure is: (tablename : articles)
    Id - title - content

    So how can I make a PHP Script that whenever is loaded, to choose a random ID from that table and displays the article ???
    Thank you in advance ...
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    rand()

    use rand and a range with the ID it will pick a random table
    where ID = rand()
    something like that

  4. #3
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    And then, the fetching ???
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  5. #4
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    CAn anyone help ????
    Its the only thing I need to build my new Website.
    Please !!!!!!!!!!!!!!!!
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  6. #5
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    PHP Code:
    include 'db_conn.php'//connects to database
    $result mysql_query"SELECT * FROM TABLE_NAME" );
    $num_rows mysql_num_rows$result );
    print 
    "There are currently $num_rows rows in the table<P>";
    print 
    "<table border=1>\n";
    while ( 
    $a_row mysql_fetch_row$result ) )
    {
        print 
    "<tr>\n";
        foreach ( 
    $a_row as $field )
        print 
    "\t<td>$field</td>\n";
        print 
    "</tr>\n";
    }
    print 
    "</table>\n";
    mysql_close$connection ); 
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  7. #6
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Thank you ...
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com