webmasterjunkie
12-03-2004, 04:29 PM
Hi All,
I just finished my "beta" site search for one of the sites I maintain. I would appreciate it if you all could check it out and let me know what you think.
You have to go to the site map, http://www.homesearch-md.com/site_map.html to use the search, and it's on the bottom of the page. Below is the php source that searches my database and arranges the results.
I am looking for feedback on the results mainly, so anything you have to say works.
<?
$body_text = "";
$search_complete = "no";
$connection = @mysql_connect("host","username","password") or die (mysql_error());
$db_name = "mydatabase";
$search_text = $_POST['search_for'];
if ($search_text != "") {
echo "</head><body>";
echo "$body_text";
$search_result = "";
while ($search_complete == "no") {
$table_name = "pages";
$search_by = "body_text";
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE $search_by LIKE \"%%$search_text%%\"";
$result = @mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$url_link = $row['url_link'];
$url_title = $row['url_title'];
$description = $row['description'];
$body_words = $row['body_text'];
$keywords = $row['keywords'];
if ($search_text == $keywords && $search_text == $url_title && $search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $keywords && $search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $keywords) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
} else {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
}
$search_complete = "yes";
}
if ($search_result == "") {
$search_result = "
Sorry, No Matches. Try the <a href=\"http://www.homesearch-md.com/site_map.html\">Site Map</a>";
}
if ($search_complete == "yes") {
$body_text .= "$search_result";
}
}
?>
I just finished my "beta" site search for one of the sites I maintain. I would appreciate it if you all could check it out and let me know what you think.
You have to go to the site map, http://www.homesearch-md.com/site_map.html to use the search, and it's on the bottom of the page. Below is the php source that searches my database and arranges the results.
I am looking for feedback on the results mainly, so anything you have to say works.
<?
$body_text = "";
$search_complete = "no";
$connection = @mysql_connect("host","username","password") or die (mysql_error());
$db_name = "mydatabase";
$search_text = $_POST['search_for'];
if ($search_text != "") {
echo "</head><body>";
echo "$body_text";
$search_result = "";
while ($search_complete == "no") {
$table_name = "pages";
$search_by = "body_text";
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE $search_by LIKE \"%%$search_text%%\"";
$result = @mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$url_link = $row['url_link'];
$url_title = $row['url_title'];
$description = $row['description'];
$body_words = $row['body_text'];
$keywords = $row['keywords'];
if ($search_text == $keywords && $search_text == $url_title && $search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $keywords && $search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $keywords) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
if ($search_text == $description) {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
} else {
$search_result .= "<font face=\"Arial\">
<a href=\"$url_link\">$url_title</a>
$description
</font>";
}
}
$search_complete = "yes";
}
if ($search_result == "") {
$search_result = "
Sorry, No Matches. Try the <a href=\"http://www.homesearch-md.com/site_map.html\">Site Map</a>";
}
if ($search_complete == "yes") {
$body_text .= "$search_result";
}
}
?>