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 -~----------~----~----~----~------~----~------~--~---
