Re: Change from loop to single query

2004-01-02 Thread Bob Terrell
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 tha

re: Change from loop to single query

2004-01-02 Thread Jonathan Villa
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; UP

re: Change from loop to single query

2004-01-02 Thread Jeremy March
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 = $qu

Re: Change from loop to single query

2004-01-02 Thread Douglas Sims
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 commas

Re: Change from loop to single query

2004-01-02 Thread Tobias Asplund
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 th

RE: Change from loop to single query

2004-01-02 Thread John McCaskey
Try forming the query with only the first array element, then iteratring through the rest concatinating OR clauses onto the end of the query. And then after the loop sending the query to the db. See my below pseudo code. String query = "UPDATE users SET status = no WHERE name = array[0]" While(a