0) { if ($word == "not") { # # $i++ kicks us to the actual keyword that the 'not' is working against, etc # $i++; if ($i == 1) { #invalid sql syntax to prefix the first check with and/or/not $buffer = bq_make_subquery($fields, $wordarray[$i], "not"); } else { $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], "not"); } } else { if ($word == "or") { $i++; if ($i == 1) { $buffer = bq_make_subquery($fields, $wordarray[$i], ""); } else { $buffer = " OR " . bq_make_subquery($fields, $wordarray[$i], ""); } } else { if ($word == "and") { $i++; if ($i == 1) { $buffer = bq_make_subquery($fields, $wordarray[$i], ""); } else { $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], ""); } } } } } else { if ($i == 0) { # 0 instead of 1 here because there was no conditional word to skip and no $i++; $buffer = bq_make_subquery($fields, $wordarray[$i], ""); } else { $buffer = " OR " . bq_make_subquery($fields, $wordarray[$i], ""); } } $output = $output . $buffer; } return $output; } # # Generates a simple boolean query. Use bq_make_query directly if you need to # add further levels of complexity (the output of bq_make_query can be and/or/etc'd # with any other output of bq_make_query) # # # $return_fields == The fields you want the query to return. # "blah1 blah2 blah3" --> "SELECT blah1, blah2, blah3...." # # $tables == The tables you want the query to... query. # "t1 t2 t3" --> "FROM t1, t2 # function bq_simple ($return_fields, $tables, $check_fields, $query_text) { # # Convert from space deliniated to comma deliniated for the query # $return_fields = str_replace(" ", ", ", $return_fields); $tables = str_replace(" ", ", ", $tables); # # build the query itself # $query = "SELECT $return_fields FROM $tables WHERE "; $query = $query . bq_make_query($check_fields, $query_text); $query = $query . ";"; # # Uncomment to debug # echo $query; return $query; } # Example usage to generate boolean query: #echo bq_simple("hat cat mat", "seuss", "hat cat", "sam +i +am or \"I do not like them in a house\""); ?>