Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.