NextGenForum.net Posted October 26, 2007 Share Posted October 26, 2007 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 ) Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted October 26, 2007 Share Posted October 26, 2007 Not really... define "random". Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 26, 2007 Author Share Posted October 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted October 26, 2007 Share Posted October 26, 2007 You could union them and pick a random one... that would be quite slow. Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 26, 2007 Author Share Posted October 26, 2007 i wudnt know where to start, could you tell me, THanks also how long?? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 26, 2007 Share Posted October 26, 2007 Is your UID key distribution "even" (i.e. not too many deleted rows?)? Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 26, 2007 Author Share Posted October 26, 2007 well i only have 2 entries, 1 and 2 being there ids, if by UIDs you mean unique id's - primary keys? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 26, 2007 Share Posted October 26, 2007 Yes, that's right... I want to know of I get the MIN/MAX of the ID field, and pick a random one, will be really be "random". Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 26, 2007 Author Share Posted October 26, 2007 will be really be "random".????? sorry dont get you there, sorry :-\ Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 27, 2007 Author Share Posted October 27, 2007 i could do with some help! Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 28, 2007 Author Share Posted October 28, 2007 please help fenway, Quote Link to comment Share on other sites More sharing options...
fenway Posted October 29, 2007 Share Posted October 29, 2007 will be really be "random".????? sorry dont get you there, sorry :-\ Yes... is the PK auto-increment? Do you delete records? Is the key distribution even? Quote Link to comment Share on other sites More sharing options...
NextGenForum.net Posted October 29, 2007 Author Share Posted October 29, 2007 yea the pk is aut-incremetn, and the key distribution is even yes, Quote Link to comment Share on other sites More sharing options...
fenway Posted October 29, 2007 Share Posted October 29, 2007 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 "); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.