I have a loop which is similar to the following:
while(array contains elements) {
UPDATE users SET status = no WHERE name = array[i]
}
great, it works but the query runs many times. I want to make only one
call to the database and have all the elements in the array be included
in the query
--
:17 AM
To: [EMAIL PROTECTED]
Subject: Change from loop to single query
I have a loop which is similar to the following:
while(array contains elements) {
UPDATE users SET status = no WHERE name = array[i]
}
great, it works but the query runs many times. I want to make only one call
to the database
On Fri, 2 Jan 2004, Jonathan Villa wrote:
I have a loop which is similar to the following:
while(array contains elements) {
UPDATE users SET status = no WHERE name = array[i]
}
great, it works but the query runs many times. I want to make only one
call to the database and have all the
You probably want the IN comparison operator
(http://www.mysql.com/doc/en/Comparison_Operators.html)
For example:
UPDATE users SET status=no WHERE name IN ('Joe', 'Wally', 'Bob', 'Cynthia');
Of course, you can create this statement from the list of names by
joining all of the names with
What language are you using? It's not clear from your example what language
you're using (no $s, but you also forgot to increment your array so?), so
I'll give you an example in PHP:
$query_string = implode( OR name = , $yourarray);
mysql_query(UPDATE users SET status = no WHERE name =
It wasn't code, just an example to get my question across clearly...
I will try the IN, however the manual says Returns 1 if expr is any of
the values in the IN list I want to do it for every value. So I'm
trying to accomplish this in one query:
UPDATE users SET status = no WHERE name = bob;
on 1/2/04 12:40 PM, Jeremy March wrote:
What language are you using? It's not clear from your example what language
you're using (no $s, but you also forgot to increment your array so?), so
I'll give you an example in PHP:
You can still do better than that. IN will be more readable than a