Re: More problems with searching

From: Date: Thu, 01 Jul 2004 18:07:02 +0000
Subject: Re: More problems with searching
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-35083@lists.php.net to get a copy of this message
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=substr($query,-4); or... $query = "Select * from keyword where "; $words = explode(' ',$_GET['search_text']); $andconde=0; foreach($words as $word) { $query .= ($andcode++) ? " and keyword = '$word'" : " keyword = '$word'"; } or... $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, Pablo

« previous php.db (#35083) next »