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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php