LanceT Posted July 10, 2007 Share Posted July 10, 2007 Here is fenway's code SELECT * FROM tablename WHERE id >= FLOOR( RAND( ) * ( SELECT MAX( id ) FROM tablename ) ) ORDER BY id ASC LIMIT 1 My original code was SELECT * FROM tablename WHERE (hello='1' OR hello2='1') But how do I add the second where query to the first code? I tried simply pasting it into the query and it didn't work. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/ Share on other sites More sharing options...
bubblegum.anarchy Posted July 10, 2007 Share Posted July 10, 2007 Probably something like this: SELECT * FROM tablename WHERE ( hello = '1' OR hello2 = '1' ) AND id >= FLOOR( RAND( ) * ( SELECT MAX( id ) FROM tablename ) ) ORDER BY id ASC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-294788 Share on other sites More sharing options...
LanceT Posted July 10, 2007 Author Share Posted July 10, 2007 I get a Parse error: syntax error, unexpected T_STRING After doing that. Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-294809 Share on other sites More sharing options...
LanceT Posted July 10, 2007 Author Share Posted July 10, 2007 Heres the whole code so you guys can see if I typed something in wrong $buddyquery = mysql_query(SELECT * FROM buddies WHERE (requester='$user' OR requestee='$user') AND id >= FLOOR( RAND( ) * ( SELECT MAX( id ) FROM buddies ) ) ORDER BY id ASC LIMIT 6); Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-294833 Share on other sites More sharing options...
bubblegum.anarchy Posted July 11, 2007 Share Posted July 11, 2007 Add quotes to the query string. Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-294914 Share on other sites More sharing options...
LanceT Posted July 11, 2007 Author Share Posted July 11, 2007 oh man I am stupid. Wow. Wow. :-X Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-295443 Share on other sites More sharing options...
LanceT Posted July 11, 2007 Author Share Posted July 11, 2007 OK now theres a new problem. Since I wanted 6 random entries to show, now its only giving me sometimes 3-4 entries. Please help! Quote Link to comment https://forums.phpfreaks.com/topic/59339-question-about-order-by-rand-alternative/#findComment-295450 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.