Hello Shiloh,

Ideas?... forget the " 1 "

$query = "Select * from keyword where ";
$words = explode(' ',$_GET['search_text']);
foreach($words as $word)
  { $query .= " keyword = '$word' and "; }


$query = "Select * from keyword where ";
$words = explode(' ',$_GET['search_text']);
foreach($words as $word)
  { $query .= ($andcode++) ? " and keyword = '$word'" : " keyword = '$word'"; }


$words = explode(' ',$_GET['search_text']);
$query = "Select * from keyword where keyword = '" . array_shift($words) . "'";
foreach($words as $word)
  { $query .= " and keyword = '$word'"; }

SM> After the very kind help i was given last night I have the query being built
SM> right, however the query does not work. Just to refresh, the gentlemen who
SM> had helped me suggested creation of a query that looks like:

SM> SELECT * FROM table1 where 1 or cat or dog...and so forth. Now, this query
SM> is building fine, but the where 1 is causing it to return rows even if it
SM> has none of the search terms. When i run it in sql without the where 1 it
SM> works as it should, but with that, i get all rows returned. Is there a way i
SM> can reword this query or am I doing something wrong?

SM> this was Mr Holmes's solution (in part):
SM> $query = "SELECT * FROM keyword WHERE 1 "
SM> $words = explode(' ',$_GET['search_text']);
SM> foreach($words as $word)
SM> { $query .= " AND keyword = '$word' "; }

SM> Ideas?

SM> Shiloh

Best regards,

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to