Since I see Larry Garfield has looked at this list today, I thought I would ask this now since I just had this come up. I know about the new ":label" for substitution in D7 and have no problem with that. But what do I do with an array of values, as in: $types = variable_get('my_types_list', array()); $args += $types; $result = db_query(..., $args); Yes, I properly used db_placeholders to set the "%s" values in place. The query works fine in D6, it's just that I am already looking at teh upgrade and wondered about how to do arrays of values like this, when I can't go in and add a label to them. Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
Hi On Wed, Aug 26, 2009 at 8:11 PM, Nancy Wichmann<nan_wich@bellsouth.net> wrote:
Since I see Larry Garfield has looked at this list today, I thought I would ask this now since I just had this come up.
I know about the new ":label" for substitution in D7 and have no problem with that. But what do I do with an array of values, as in: $types = variable_get('my_types_list', array()); $args += $types; $result = db_query(..., $args);
Yes, I properly used db_placeholders to set the "%s" values in place. The query works fine in D6, it's just that I am already looking at teh upgrade and wondered about how to do arrays of values like this, when I can't go in and add a label to them.
You can use a single placeholder and an array of values and it will just work... '... WHERE your_field IN (:values)', array(':values' => $array_of_values) Berdir
Sascha Grossenbacher wrote:
You can use a single placeholder and an array of values and it will just work... '... WHERE your_field IN (:values)', array(':values' => $array_of_values)
Perfect. Thanks, Sascha - and Larry (you done good). Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
note that ->condition('your_field', $array_of_values, 'IN') works too.
Karoly Negyesi wrote:
note that ->condition('your_field', $array_of_values, 'IN') works too.
Thanks. I'm still getting my head around object stuff. The DBTNG stuff looks really powerful. I wish there was a "Drupal Objects for Idiots." Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
On Wednesday 26 August 2009 2:33:26 pm Nancy Wichmann wrote:
Karoly Negyesi wrote:
note that ->condition('your_field', $array_of_values, 'IN') works too.
Thanks. I'm still getting my head around object stuff. The DBTNG stuff looks really powerful. I wish there was a "Drupal Objects for Idiots."
Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
There's the DBTNG docs in the handbook, which could always use feedback. :-) I also will be doing a DBTNG BoF in Paris on the 1st. Also, I think catch deserves more thanks than I do for the auto-array- expansion in static queries, but since he's currently traveling I'll say thank you on his behalf. :-) -- Larry Garfield larry@garfieldtech.com
I don't know what you are trying to do, but it would probably be better served by a dynamic query, using the values() method. Could you post an example of the whole query, and the code to build the arguments? -Mike __________________ Michael Prasuhn 503.512.0822 office mike@mikeyp.net http://mikeyp.net On Aug 26, 2009, at 2:11 PM, Nancy Wichmann wrote:
Since I see Larry Garfield has looked at this list today, I thought I would ask this now since I just had this come up.
I know about the new ":label" for substitution in D7 and have no problem with that. But what do I do with an array of values, as in: $types = variable_get('my_types_list', array()); $args += $types; $result = db_query(..., $args);
Yes, I properly used db_placeholders to set the "%s" values in place. The query works fine in D6, it's just that I am already looking at teh upgrade and wondered about how to do arrays of values like this, when I can't go in and add a label to them.
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
Sascha handled it. Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
participants (5)
-
Karoly Negyesi -
Larry Garfield -
Michael Prasuhn -
Nancy Wichmann -
Sascha Grossenbacher