RE: [PHP-DB] Search Query

From: Date: Thu, 18 Dec 2003 10:06:54 +0000
Subject: RE: [PHP-DB] Search Query
Groups: php.db 
Request: Send a blank email to php-db+get-32111@lists.php.net to get a copy of this message
On 18 December 2003 05:26, Ng Hwee Hwee wrote: > Dear all, > > i need help with my search query statement.. what is wrong > with my code? Nothing obvious that I can see, except a little inefficiency. Where do $keyword and $table come from? -- is this a register_globals issue? > <snip> > $word = split(" ", $keyword); > $num_words = count($word); > $word_str = ""; > $criteria = ""; > > for ($i=0; $i<$num_words; $i++) > { > if ($i) > $word_str .= "and colName like '%".$word[$i]."%' "; > > else $word_str .= "colName like '%".$word[$i]."%' "; > > } > $word_str .= "and col2 = '$foo' "; > > $criteria .= "$word_str "; I'd replace all of the above with: $criteria = "colName like '%" . str_replace(' ' , "%' and colName like '%" , $keyword) . "%'" . " and col2 = '$foo' " > $table .= "db_table"; > > $query = "select * from ".$table." where ".$criteria; </snip> > > when i try to echo $query, i get --- select * from where > > and so of course MySQL gives me an error 1064 near ' where ' > > what happened? What's your error_reporting level? HAve you tried cranking it up to E_ALL to see if any relevant warnings are being generated that you're not currently seeing? Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.db (#32111) next »