I've created a MySQL search engine in php (a very simple one) and I want it to search for words inside a feild rather than search the entire feild. The search engine I have now only accomodates for exact phrase matching (eg. when you search for "anna friel" it returns the record with the name value equal to "anna friel" [case-insensitive], but when you search for "anna" it returns no records). This is acceptable until names like "adriana sklenarikova" come along, which is a pretty hard name to remember off by heart, especially for my intended market.
What I want to create is a search engine that searches through search scripts in a MySQL feild which are seperated by commas. For example, lets say that I have a MySQL table with a feild called "search". In that feild is a series of search strings seperated by commas (eg. "adriana,sklenarikova,adriana sklenarikova,adriana karembeau,karembaeu,etc...". I want the search engine to take a search query of "adriana" and return all the records with the search string "adriana" inside the search feild of the MySQL table. Is this even possible?
My MySQL search script
-------------------------------------------
<html><title>Search</title><body>
<?php
$db = mysql_connect("localhost", "username","password" or die ("Could not connect to server"
@mysql_select_db("planetmirror_db",$db) or die ("Could not connect to database"
$query = "SELECT * FROM celebdb WHERE name LIKE '$search' ";
$result = mysql_query($query,$db) or die ("Could not connect to table"
if ($myrow = mysql_fetch_array($result)) {
printf("<b>Name:</b> %s<br>\n", mysql_result($result,0,"name");
printf("<b>DOB:</b> %s<br>\n", mysql_result($result,0,"dob");
printf("<b>Feild:</b> %s<br>\n", mysql_result($result,0,"feild");
printf("<b>Description:</b> %s<br>\n", mysql_result($result,0,"desc");
printf("<b>Pic Location:</b> %s<br>\n", mysql_result($result,0,"picloc");
printf("<b>File Location:</b> %s<br>\n", mysql_result($result,0,"fileloc");
}
else {
printf("Sorry, no records found\n"
}
?>
</body></html>
-----------------------------------------
Note: The variable $search is defined previously by a form which puts the variable in the url.
What I want to create is a search engine that searches through search scripts in a MySQL feild which are seperated by commas. For example, lets say that I have a MySQL table with a feild called "search". In that feild is a series of search strings seperated by commas (eg. "adriana,sklenarikova,adriana sklenarikova,adriana karembeau,karembaeu,etc...". I want the search engine to take a search query of "adriana" and return all the records with the search string "adriana" inside the search feild of the MySQL table. Is this even possible?
My MySQL search script
-------------------------------------------
<html><title>Search</title><body>
<?php
$db = mysql_connect("localhost", "username","password" or die ("Could not connect to server"
@mysql_select_db("planetmirror_db",$db) or die ("Could not connect to database"
$query = "SELECT * FROM celebdb WHERE name LIKE '$search' ";
$result = mysql_query($query,$db) or die ("Could not connect to table"
if ($myrow = mysql_fetch_array($result)) {
printf("<b>Name:</b> %s<br>\n", mysql_result($result,0,"name");
printf("<b>DOB:</b> %s<br>\n", mysql_result($result,0,"dob");
printf("<b>Feild:</b> %s<br>\n", mysql_result($result,0,"feild");
printf("<b>Description:</b> %s<br>\n", mysql_result($result,0,"desc");
printf("<b>Pic Location:</b> %s<br>\n", mysql_result($result,0,"picloc");
printf("<b>File Location:</b> %s<br>\n", mysql_result($result,0,"fileloc");
}
else {
printf("Sorry, no records found\n"
}
?>
</body></html>
-----------------------------------------
Note: The variable $search is defined previously by a form which puts the variable in the url.