Re: Using an array(-ish) in SQL queries
| From: | -{ Rene Brehmer }- | Date: | Wed, 03 Nov 2004 04:05:24 +0000 |
| Subject: | Re: Using an array(-ish) in SQL queries | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37165@lists.php.net to get a copy of this message | ||
At 02:37 03-11-2004, Jennifer Goodie wrote:
[snip] My current version generates, for multi-select cases, queries like this: DELETE FROM the_table WHEREthanks a whole bunch ... can't believe how close I was ... and I couldn't even find it in the manual :-/ and for some reason I've never thought of implode :-s ... anyways, live and learn ... thanks :) Rene -- Rene Brehmer aka Metalbunny If your life was a dream, would you wake up from a nightmare, dripping of sweat, hoping it was over? Or would you wake up happy and pleased, ready to take on the day with a smile? http://metalbunny.net/ References, tools, and other useful stuff... Check out the new Metalbunny forums at http://forums.metalbunny.net/ID='1' OR ID='2' ORID='3' ORID`='4' ORID='5' ORID='6' or similar with the SELECT statement. [snip lots of stuff] DELETE FROM the_table WHEREIDISIN(1,2,3,4,5,6) use IN http://dev.mysql.com/doc/mysql/en/Comparison_Operators.html#IDX1268 If you know all the values in the array are escaped and safe you can just use implode() to make the list for IN $string = implode("','",$array); $sql = "SELECT FROM $table WHERE col_name IN('$string')"; Notice I added single quotes around the string, that is because they will be missing since implode only sticks the string between array elements. However, you'd need a join that makes sense for a multi-table delete. I don't know if it will work with a union, I have never tried, maybe somone else will chime in.