Posted: Sat Jan 30, 1999 6:18 pm Post subject: 2 Problems with PHP3&MySQL
Hi, I've some troubles in making a search engine for a web site:
1) I don't know how to make a boolean search (AND/OR) using 2 or more inputs taken from only one field in a search form. Example: I write in the field "TEST FILE". Actualy the engine look for both togheter, I'd like to have a search for "TEST" "FILE" and "TEST FILE".
2) If there's no data matching the input I get a "0 in not a mysql ......." or "The document contain no data"
How can I show a message to the user instead of these ?
Posted: Sat Jan 30, 1999 10:52 pm Post subject: RE: 2 Problems with PHP3&MySQL
Hi
Both questions seem simple enough :
1. Lets say the form parameter is called "search". When someone does the search for "TEST FILE" you get a variable called $search which has a value of "TEST FILE".
All you need to do now is get the word "TEST" and the word "FILE" out of the string. You can do this like this :
$WORDS=explode(" ", $search);
Now you have an array which has the word "TEST" in $WORDS[0] and the word "FILE" in $WORDS[1].
Now you need to make a query for each of the words and a query for the original $search string.
2. before you do anything, check to see if the query returned any data. if you work with MySql you just need to do :
$query=mysql_query("SELECT * FROM.....") or die("Can't Preform query");
if (!mysql_num_rows($query))
echo"no results found"
else....
This is the general idea but you will need to make some kind of counter cause you will have more than one query. if the counter will still be 0 after the last query then you can echo a message about no results...
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum