henricar Posted April 28, 2011 Share Posted April 28, 2011 hey everyone, I am trying to fetch an array using the WHERE condition. What I would like to do is set the WHERE equal to multiple values (as an array). This is the code I have but it doesn't seem to be working.. could anyone please help me? Thank you! $fetchfol = mysql_query("SELECT * FROM following WHERE bywho='$currentuserid'"); $folarray = mysql_fetch_array($fetchfol); $folarray = $folarray['followwho']; $fetchsresults = "SELECT * FROM posts WHERE (bywho = '$folarray') ORDER BY popularity DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/ Share on other sites More sharing options...
requinix Posted April 29, 2011 Share Posted April 29, 2011 What you need to do is use a JOIN, actually. SELECT p.* FROM posts p JOIN following f ON p.bywho = f.followwho WHERE f.bywho = $currentuserid ORDER BY p.popularity DESC And it should be "whom". Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1207952 Share on other sites More sharing options...
Muddy_Funster Posted April 29, 2011 Share Posted April 29, 2011 In addition, you should avoid using SELECT * and don't needlesly/lazily alias tables to meeningless single letters. Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1208050 Share on other sites More sharing options...
requinix Posted April 29, 2011 Share Posted April 29, 2011 don't needlesly/lazily alias tables to meeningless single letters. Why not? Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1208249 Share on other sites More sharing options...
fenway Posted May 1, 2011 Share Posted May 1, 2011 Because typing doesn't cost anything but clarity. Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1209136 Share on other sites More sharing options...
requinix Posted May 2, 2011 Share Posted May 2, 2011 If I want a couple fields specifically, sure. But where's the clarity in typing out everything by hand? SELECT post_id, topic_id, forum_id, poster_id, icon_id, poster_ip, post_time, post_approved, post_reported, enable_bbcode, enable_smilies, enable_magic_url, enable_sig, post_username, post_subject, post_text, post_checksum, post_attachment, bbcode_bitfield, bbcode_uid, post_postcount, post_edit_time, post_edit_reason, post_edit_user, post_edit_count, post_edit_locked FROM phpbb_posts... Compare that with SELECT * FROM phpbb_posts Will I use every field that comes back? Maybe not. But I'd much rather have extra data than maintain a gigantic list of fields. Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1209556 Share on other sites More sharing options...
fenway Posted May 3, 2011 Share Posted May 3, 2011 The comment was with respect to aliases, not column lists. "Extra data" is fine for normal, under-utilized sites -- besides, most DB wrappers can help you. Quote Link to comment https://forums.phpfreaks.com/topic/235042-select-function-where-array/#findComment-1209724 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.