Jump to content

Random selection from a database.


NextGenForum.net

Recommended Posts

Hi,

 

I run a site - www.selectgreen.co.uk and as you can see there is a section called featured company. I want to pull out a random entry from about 11 databses altogether in order for it to show up as a featured company everyday.

 

I dont know if this is possible, but help appreciated (hope im clear here  ;D)

 

Thanks

 

Link to comment
Share on other sites

I mean that every day, i want a different company to appear. I have 11 databases one for each category (property, music etc...) So i need to somehow pull out an entry from one of these databases to appear in the featured company box.

 

i probably havent made my self any clearer, but thats the best i can explain it. sorry

Link to comment
Share on other sites

If so, then get back min/max of the uid field for the table, and pick one "in the middle":

 

$range_result = mysql_query( " SELECT MAX(`id`) AS max_id , MIN(`id`) AS min_id FROM `table` ");
$range_row = mysql_fetch_object( $range_result );
$random = mt_rand( $range_row->min_id , $range_row->max_id );
$result = mysql_query( " SELECT * FROM `table` WHERE `id` >= $random LIMIT 0,1 ");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.