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 4 of 4
  1. #1
    Member Tevek's Avatar
    Join Date
    Aug 2004
    Location
    UK
    Posts
    32
    Member #
    7215
    I need to be able to select 4 records randomly from a mysql table, not connected to eachother specifically. They do use an ascending number key but the trouble is that as records get deleted every now and then it's not consistently rising. Any ideas?

    Thanks,

    Gawain.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well, get the number of rows in the table..

    PHP Code:
    select count(*) FROM tablename 
    Then get four random numbers using that number as the upper bound.

  4. #3
    Member Tevek's Avatar
    Join Date
    Aug 2004
    Location
    UK
    Posts
    32
    Member #
    7215
    Quote Originally Posted by bfsog
    Well, get the number of rows in the table..

    PHP Code:
    select count(*) FROM tablename 
    Then get four random numbers using that number as the upper bound.

    That's good, but is there a way of selecting a record by just the record number it is as the ID wouldn't be consistent

  5. #4
    Member Tevek's Avatar
    Join Date
    Aug 2004
    Location
    UK
    Posts
    32
    Member #
    7215
    Sorry, just realised how I can, thanks!


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 10:51 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com