MDanz Posted August 19, 2010 Share Posted August 19, 2010 how do i run a query for a variable with multiple values? i've been told a loop is not the right way to do it, which is the way i've been doing it and it has worked. I assumed putting it in a foreach loop would accomplish looping the query for variable with multiple values. e.g. testa and testb are both in the array, $key. foreach($key as $value) { //mysql query } How do i run a single query not in a loop that will have both 'testa' and 'testb' in the WHERE clause? Quote Link to comment https://forums.phpfreaks.com/topic/211175-mysql-where-clause-variable-help/ Share on other sites More sharing options...
mikosiko Posted August 19, 2010 Share Posted August 19, 2010 post your table description and what do you want to get Quote Link to comment https://forums.phpfreaks.com/topic/211175-mysql-where-clause-variable-help/#findComment-1101232 Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2010 Share Posted August 19, 2010 MDanz, if you had continued this in your existing thread instead of starting a new thread, people would not need to be asking you questions about what it is you are doing and what your tables/data looks like. By starting a new thread you are throwing away the information about how you got to this point. That just wastes time and reduces the number of replies you are likely to get. Quote Link to comment https://forums.phpfreaks.com/topic/211175-mysql-where-clause-variable-help/#findComment-1101242 Share on other sites More sharing options...
johnsmith153 Posted August 20, 2010 Share Posted August 20, 2010 SELECT field FROM $table WHERE field2 = 'testa' || field2 = 'testb' or SELECT field FROM $table WHERE field2 IN ('testa', 'testb') The second one returns records where testa or testb match field2. You can produce a long list of values here if you wish. Quote Link to comment https://forums.phpfreaks.com/topic/211175-mysql-where-clause-variable-help/#findComment-1101503 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.