laPistola Posted November 22, 2008 Share Posted November 22, 2008 Can you use arrays in WHERE ie would this work $myArray = array('1','3','26'); WHERE id = '$myArray' Would it return the record id 1,3 & 26 ? Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/ Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 You can use the reserved word IN, never tried it with a SELECT but it should work all the same. All you need to do is implode the array and use a comma as the separator. <?php $array = array("1","3","26"); mysql_query("SELECT * FROM table WHERE id IN ('" . implode(",",$array) . "')") or die("Error: ".mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-696146 Share on other sites More sharing options...
laPistola Posted November 22, 2008 Author Share Posted November 22, 2008 Right, my array is built from a string ie $string = "1,3,26"; $myArray = array($string); so if i used IN in my syntext i could skip implode (so there is less code) by doing the following WHERE id IN '$string' is this correct?? Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-696150 Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 Yeah, should work. No need to make it an array. And declaring it like that probably wouldn't make it an array anyway. You should be exploding it where the comma is the delimiter. But as for your question, no you don't need to implode, and you don't need to make it an array. Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-696155 Share on other sites More sharing options...
laPistola Posted November 22, 2008 Author Share Posted November 22, 2008 Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-696159 Share on other sites More sharing options...
laPistola Posted November 24, 2008 Author Share Posted November 24, 2008 Worked great thank you Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-697302 Share on other sites More sharing options...
laPistola Posted November 28, 2008 Author Share Posted November 28, 2008 OK this didn't work properly, i have only come to try and get more then one row out if it did i see its only seeing the first number. so i changed it to this to test "SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN ('6,8') ORDER BY username ASC" 6 and 8 are in the database and when i echo mysql_num_rows it shows up at 1 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-701150 Share on other sites More sharing options...
corbin Posted November 28, 2008 Share Posted November 28, 2008 "SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN ('6,8') ORDER BY username ASC" Your format is wrong. You're currently passing 1 thing to IN. "SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN (6, ORDER BY username ASC" Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-701203 Share on other sites More sharing options...
laPistola Posted November 28, 2008 Author Share Posted November 28, 2008 Thank you end result was SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN (".implode(',',$FLabba).") ORDER BY username ASC Works fine now so it seems. Oh your right Vista dont suck, i wouldn't go back to even leopard now i have vista Quote Link to comment https://forums.phpfreaks.com/topic/133770-solved-just-a-quick-one/#findComment-701239 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.