This is what I ended up with and works.
function __quickQuery($string, $rank, $auth)
{
//create an array of search terms if more than 1 was
entered
$string = split(",", $string);
$i=0; // This is each counter
// Now build your SQL String
$sql = "";
foreach ($string as $key => $value)
{
$value = trim($value);
//strip white space befor and after each term
$sql.= "Post.title LIKE '%" . $value . "%' OR
Post.description LIKE '%" . $value . "%'";
$i++; // Put your counter up by 1
if($i < count($string)) // Check if your counter is
smaller than amount of values in array, if there are still values, add a OR
{
$sql.=" OR ";
}
}
$params = array(
'conditions' =>
array('Post.status' => 0 , 'Post.rank <=' => $rank, $sql),
............ So on
and on
)));
$q = $this->find('all', $params);
return $q;
}
Pass the $sql to the conditions and I end up with
Post.title LIKE '%mary%' OR Post.description LIKE '%mary%' OR Post.title
LIKE '%test%' OR Post.description LIKE '%test%' OR Post.title LIKE
'%something%' OR Post.description LIKE '%something%'
-----Original Message-----
From: Luke [mailto:[email protected]]
Sent: August-12-09 1:45 PM
To: CakePHP
Subject: Re: Search function
You are missing a few OR in your below text, I have tried it out and get all
the needed OR, did you just keft it out below or what is the issue?
Oh and by the way of course you will need a WHERE aswell in the first part
$sql = "SELECT * FROM table"; I forgot that one.
On 12 Aug., 17:00, "Dave Maharaj :: WidePixels.com"
<[email protected]> wrote:
> Yeah that's the basic idea to build the "Post.title LIKE '%" . $value.
"%'
> OR Post.description LIKE '%" . $value . "%' "; string from the user
> submitted text
>
> So if there are 3 words it ends up "Post.title LIKE '%" . $value. "%'
> OR Post.description LIKE '%" . $value . "%' ";"Post.title LIKE '%" .
$value.
> "%' OR Post.description LIKE '%" . $value . "%' ";"Post.title LIKE '%" .
> $value. "%' OR Post.description LIKE '%" . $value . "%' ";
>
>
>
> -----Original Message-----
> From: Luke [mailto:[email protected]]
> Sent: August-12-09 11:43 AM
> To: CakePHP
> Subject: Re: Search function
>
> Hi Dave,
>
> Maybe not the nicest solution, but this should work:
>
> $i=0; // This is your counter
>
> // Now build your SQL String
> $sql = "SELECT * FROM table";
>
> foreach ($string as $key => $value)
> { $value = trim($value);
>
> //strip white space befor and after each term
> // $value = trim($string[$i]);
> $sql.= "Post.title LIKE '%" . $value. "%' OR
> Post.description LIKE '%" . $value . "%' ";
>
> $i++; // Put your counter up by 1
> if($i < count($string)) // Check if your counter is smaller than
> amount of values in array, if there are still values, add a OR
> {
> $sql.="OR";
> }
> }
>
> You can try out by putting in echo $sql at the end.
>
> Is this what you were looking for or did I missunderstood?
>
> Luke- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---