Perhaps I'm over-complicating this but I'm still having some problems with
building my query.

I'm looking to do something like:

$array = array (A, B, C, D, E);
$list = implode( ',' , $array);

'conditions' => array(
                               'SomeCol.contents' => array($list)
                             )

The problem I'm running into is that $array can contain any number and
combination of values (A, C, E), (A, B), (E) ... etc.
And 'SomeCol.contents' can also contain any number and combination of values
stored as a comma separated string. (it was originally stored as a
serialized array).

I need the query to return a result if 'SomeCol.contents' and $array have
any one of their values in common.

I was thinking along the lines of :

'conditions' => array(
                               'SomeCol.contents LIKE' => '%'.$array[0].'%'
                                                         OR
                                'SomeCol.contents LIKE' => '%'.$array[1].'%'
   etc, etc // this way should include any record in the result that shares
a value with $array

but I assume I would run into an issue with an undefined index by not
knowing how many values $array contains. (I do know it has the potential to
store a max of 7 values)

I had this all worked out with conventional PHP but now I need to use
Paginate and containable with this query as well as a bunch of other
conditions (with a set value) and I'm confusing myself more than anything
else which isn't a real stretch for me to begin with 8-).

Any suggestions are appreciated.

Thanks.

- Ed

On Fri, Jun 4, 2010 at 11:54 PM, Ed Propsner <crotchf...@gmail.com> wrote:

> Thanks Calvin, point well taken. I'll just stick with GET like I always
> have for searches.
>
> I tweaked the routing and got things cleaned up a bit so I guess I'm okay
> with it.
> I'm not quite sure what I was expecting in the first place? 8-)
>
> The search uses a lot of checkboxes and results in something like
> http://mysite.com/search/results/value1=0&value1=1&value2=0&value2=1.
> I can't seem to clean it up any more when submitting with GET, or am I
> still missing something?
>
> Anyhow, at least it's working the way that I want it to. I'm still having
> some issues with query so I'll quit fussing with the url for now.
>
> - Ed
>
>
> On Fri, Jun 4, 2010 at 10:15 PM, calvin <cal...@rottenrecords.com> wrote:
>
>> POST requests are generally not cached, but you can force it to be
>> cached using the Cache-Control and Expires headers. However, I've
>> never tried this so I don't know if the browser will still show the
>> form submission dialog (it may need to resend the form data to check
>> to see if the document has changed since last requested). It probably
>> won't, but I would still strongly advise against this.
>>
>> A search request is generally an idempotent operation (multiple
>> requests do not have any side-effects), which is precisely what the
>> GET request is designed for. There's no reason to use POST in this
>> case. Cake has a perfectly good way of hiding ugly URL-encoding using
>> its REST-style routing patterns, e.g.:
>>
>> http://yoursite.com/pages/search/foo/bar/foo2/bar2/...
>>
>> You can also use named parameters to make the search URL more
>> readable, e.g.:
>>
>>
>> http://yoursite.com/products/search/q:paegan/artist:acid+bath/category:t-shirt
>>
>> Unless you have a ton of search options, I see no reason to use POST.
>> And even if you use POST and generate shorter/cleaner URL--what's the
>> point? What will that clean URL achieve? The user can't bookmark it.
>> They can't link a friend to it. They can't do anything with it.
>>
>> A happy compromise would be to do what a lot of forums do, and cache
>> each search server-side. Then when the user performs a search (with
>> either POST or GET), they get redirected to the cached search result,
>> which might be something like:
>>
>> http://yoursite.com/search/paegan+terrorism+tactics/f83e3a4b389c6b
>>
>> That will decrease your server load, allow you to use a POST form, and
>> still allow the user to bookmark/link the search results (at least for
>> a time).
>>
>> On Jun 4, 10:40 am, Ed Propsner <crotchf...@gmail.com> wrote:
>> > I was checking out the book on complex queries and not really finding
>> what
>> > I'm looking for.
>> >
>> > I'm trying to create a query that covers both a basic and advanced
>> search.
>> > The form may be submitting all or just some of the options available on
>> the
>> > page depending on what the user chooses.
>> >
>> > Once the form has been submitted clicking any one of the query results
>> would
>> > navigate the user away from the 'results page'.
>> >
>> > To avoid getting hit with the "form submission" dialogue when the users
>> > clicks the back button to return to the search results page
>> > and to cover the 'conditional query' ... I used to use a combo of $_GET
>> and
>> > if(isset.
>> >
>> > ie:
>> >
>> > $query= " SELECT something FROM somewhere WHERE etc. etc. etc. AND ";
>> >
>> >    if (isset($_GET['some_value']) && $_GET['some_value'] != '' )
>> >   {
>> > $value = $_GET['some_value'];
>> > $query .= "AND  something = '".addslashes($value)."'";
>> >   }
>> >
>> > And so on.
>> >
>> > I'm not familiar with using cache for anything. To avoid using get and
>> the
>> > ugly urls would I be able to use post and cache the results also
>> avoiding
>> > the "form submission" dialogue when returning to the results page?
>> >
>> > Also, what is the best approach to setting up a 'conditional' query
>> similar
>> > to what I posted above?
>> >
>> > I'll spend some more time digging through the book and experimenting if
>> > someone can point me in the right direction.
>> >
>> > Thanks,
>> >
>> > - Ed
>>
>> Check out the new CakePHP Questions site http://cakeqs.org and help
>> others with their CakePHP related questions.
>>
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
>>  more options, visit this group at
>> http://groups.google.com/group/cake-php?hl=en
>>
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to