On 14 Jul 2003 13:11:11 +0200, you wrote: >Anyway, as you can see my problem lies with the SQl when the last >element is reached, then it should NOT add another "and" or "or".
The short answer is "implode()". >Any help with my "logic", ie, how do/would you guys do this? if ($_POST[any_all] == "any") { any_all should be a string literal or a variable name. Try cranking up your warning levels. <? function build_sql_statement($table_name, $words, $glue) { $sql = "SELECT * FROM $table_name WHERE "; $newwords = array(); for ($i = 0; $i < sizeof($words); $i++) { if ($words[$i] != 'the' && $words[$i] != 'and') { $newwords[] = "name LIKE '%" . $words[$i] . "%'"; } } $sql .= join(" $glue ", $newwords); $sql .= " ORDER BY name"; return ($sql); } $table_name = "test"; $any_all = "any"; $string = "this is the test"; /* get our logic choice */ $logic = 'AND'; if (isset($any_all) && $any_all == 'any') { $logic = 'OR'; } /* break the incoming string into single words */ $phrases = explode(" ", $string); /* generate a SQL statement from the incoming words */ $sql = build_sql_statement($table_name, $phrases, $logic); echo ($sql); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php