> The problem is that MySQL cannot/will not take a string of integers as
> a WHERE/IN clause on an INT field

Yes it will. The problem is that your aren't passing an array in, your
passing a string.

Cake automagically converts the where clause to:

.. WHERE (`Bid`.`industry_id` IN ('400,402,403') )

because you pass in the string '400,402,403'

The correct where clause should read:

.. WHERE (`Bid`.`industry_id` IN ('400','402','403') )

Which is what you get when you pass in an array.

Re-read Mikee comment for how to pass an array in.

Hope this helps :-)



On Feb 13, 10:16 am, "digitalcowboy" <[EMAIL PROTECTED]> wrote:
> The stumped part was right after what you quoted "...without Cake
> converting them to a string."
>
> The problem is that MySQL cannot/will not take a string of integers as
> a WHERE/IN clause on an INT field and Cake requires that the
> conditions parameter be a string.  No matter how I passed the values
> to Cake's query they came out with quotes around them - like a string
> - and MySQL would only "see" the first INT in the string.
>
> Thanks to everyone for your responses.  I didn't find a solution to
> the problem itself, but I figured out ways around it.
>
> On Feb 12, 3:38 pm, "Mikee Freedom" <[EMAIL PROTECTED]> wrote:
>
> > hey dood,
>
> > what do you mean by this exactly?
>
> > "I can't figure out how to fill in the values from a variable..."
>
> > If you've set up your form to pass the id's as an array :
>
> > <input type="checkbox" name="data[Object][id][]" value="1" />
> > <input type="checkbox" name="data[Object][id][]" value="2" />
> > <input type="checkbox" name="data[Object][id][]" value="3" />
>
> > when you reference :
>
> > $this->data['Object']['id']
>
> > In your controller it should already be an array. Then you could do
> > something like :
>
> > $conditions = array (
> >     'Object.id' => $this->data['Object']['id']
> > );
>
> > Which will then allow Cake to create the WHERE / IN statement.
>
> > Does that make sense?
>
> > HTH,
> > mikee
>
> > On 13/02/07, digitalcowboy <[EMAIL PROTECTED]> wrote:
>
> > > I appreciate the help but I already have that part.  The values in
> > > that array are any possible combination of 10 coming from the
> > > checkboxes in the form.  I'm trying to do exactly what you suggest but
> > > I can't figure out how to fill in the values from a variable without
> > > Cake converting them to a string.
>
> > > On Feb 12, 11:26 am, "djiize" <[EMAIL PROTECTED]> wrote:
> > > > to to a IN query, do this:
> > > > $criteria['Bid.industry_id'] = array(400,402,403);  // free to you to
> > > > populate the array
> > > > $this->Bid->findAll($criteria);
>
> > > > it will automagically do:
> > > > ... WHERE Bid.industry_id IN (400, 402, 403);
>
> > > > On 12 fév, 17:45, "BlenderStyle" <[EMAIL PROTECTED]> wrote:
>
> > > > > You could probably get around this with the query method for the
> > > > > model.
>
> > > > > $this->Model->query($custom_query);
>
> > > > > On Feb 12, 5:44 am, "digitalcowboy" <[EMAIL PROTECTED]> wrote:
>
> > > > > > I wasn't sure how to title this.  Here's my challenge:
>
> > > > > > I have an array of 10 checkboxes to select categories for a search.
> > > > > > The checkboxes are passing INT values from the form.  The search
> > > > > > function then needs to apply the checked catgeories as conditions on
> > > > > > the query.  I couldn't figure out how to pass an array as the
> > > > > > $conditions value itself.  The closest I've been able to come is 
> > > > > > doing
> > > > > > an implode on the array to create a string for $conditions.  The
> > > > > > problem is that the array values and, more importantly, the field 
> > > > > > the
> > > > > > condition is applied to are INT.  Cake is building the query like 
> > > > > > so:
>
> > > > > > ... WHERE (`Bid`.`industry_id` IN ('400,402,403') )
>
> > > > > > That's fine except that MySQL seems to be choking because of the
> > > > > > single quotes and only searching on the first value (WHERE 
> > > > > > industry_id
> > > > > > = 400 in this example).  I confirmed this by running the query
> > > > > > directly against the database.  After removing the single quotes
> > > > > > around the list of INTs - [WHERE (`Bid`.`industry_id` IN
> > > > > > (400,402,403) )] - it finds everything as it should.
>
> > > > > > Long way to get to this question:  Is there any way I can pass an
> > > > > > array of INTs for the $conditions on findAll instead of a string or
> > > > > > get MySQL to properly accept the array of INTs in string form?
>
> > > > > > Thanks in advance.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to