Search Query

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

 



Dear all,

i need help with my search query statement.. what is wrong with my code?

<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 ";
      $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?

thanx thanx!

hwee

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

  Powered by Linux