Jump to content

mysql where clause variable help


MDanz

Recommended Posts

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?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/211175-mysql-where-clause-variable-help/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.