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. 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 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. 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); 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. 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 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! 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
Archived
This topic is now archived and is closed to further replies.