Hi guys, trying to write a script here in php that will be part of a basic AJAX search feature on my webpage.
I have another search which simply pulls out users and email addresses from the database but I want to be able to search for individual words inside of a database field. For example think of doing a word search on this forum. I would imagine that each word would have to be taken individually and stored in some kind of array. Anyone able to help me code this?
The other example I have is as follows:
In the above the GET variable q is basically the content that is entered in the search field. As each letter is typed, the data is sent anscronously to the server and this script returns the results. Please note this is only a sample section of code so no stripslashes or other methods have been used. Basically what I need to know is how to search for an individual word in a given field rather than returning a whole field such as 'email' in the above example.
Hope this makes sense!
Jonny
I have another search which simply pulls out users and email addresses from the database but I want to be able to search for individual words inside of a database field. For example think of doing a word search on this forum. I would imagine that each word would have to be taken individually and stored in some kind of array. Anyone able to help me code this?
The other example I have is as follows:
Code:
if(isset($_GET['q'])) {
$searchString = $_GET['q'];
$sql = mysql_query("SELECT * FROM users WHERE username LIKE '".$_GET['q']."%' ORDER BY category ASC");
if($searchString != NULL) {
while($row = mysql_fetch_assoc($sql)) {
echo $row['username'];
echo '<br />';
echo "<a href='mailto:$row[email]'>$row[email]</a><br /><br />";
}
}
if(mysql_num_rows($sql) == 0) {
echo "<i>No results found</i>";
}
}
In the above the GET variable q is basically the content that is entered in the search field. As each letter is typed, the data is sent anscronously to the server and this script returns the results. Please note this is only a sample section of code so no stripslashes or other methods have been used. Basically what I need to know is how to search for an individual word in a given field rather than returning a whole field such as 'email' in the above example.
Hope this makes sense!
Jonny