Re: Search Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



thanx Mike for your help!!

appreciatively,
hh

----- Original Message -----
From: "Ford, Mike [LSS]" <M.Ford@xxxxxxxxx>
To: "'Ng Hwee Hwee'" <hhwee@xxxxxxxxxxx>; "DBList" <php-db@xxxxxxxxxxxxx>
Sent: Thursday, December 18, 2003 6:06 PM
Subject: RE:  Search Query


> 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@xxxxxxxxxxxxxx
> 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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux