Page 1 of 1

creating simple error message/approximate search matches

Posted: Sat Feb 15, 2003 1:22 pm
by jarow
I have a form with two search parameters (text boxes). Users may write in a species name OR common name OR both. I have two questions about this.

1. since the user writes in the information I would like the search to work even if the name isn't an exact match. In other words, if it approximates the species name or common name then I would like a list of results shown. How can I write an SQL statement to search for "approximate" matches?

2. Enclosed below is the code for my two search parameters. Where and how should I place the following error message "No matches were found" if there is no reasonable match for either species or common name.

if (isset($HTTP_GET_VARS['especie'])) {
$varespecie_rspasserine = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['especie'] : addslashes($HTTP_GET_VARS['especie']);
}
$varnomcom_rspasserine = "%";
if (isset($HTTP_GET_VARS['nomcom'])) {
$varnomcom_rspasserine = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['nomcom'] : addslashes($HTTP_GET_VARS['nomcom']);
}
mysql_select_db($database_connpasserines, $connpasserines);
$query_rspasserine = sprintf("SELECT passerines.especie, passerines.nomcom, passerines.presencia, passerines.ah, passerines.disp, passerines.dmax, passerines.tampobl, passerines.habitatp, passerines.habitats, passerines.indice, passerines.status, passerines.nota FROM passerines WHERE passerines.especie LIKE '%s' OR passerines.nomcom LIKE '%s'", $varespecie_rspasserine,$varnomcom_rspasserine);
$rspasserine = mysql_query($query_rspasserine, $connpasserines) or die(mysql_error());
$row_rspasserine = mysql_fetch_assoc($rspasserine);
$totalRows_rspasserine = mysql_num_rows($rspasserine);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $row_rspasserine['especie']; ?> <?php echo $row_rspasserine['nomcom']; ?>

Thanks very much....

Did I mention I was new at this :D ??

Jim

Posted: Sat Feb 15, 2003 6:54 pm
by Rob the R
A quick response for question #1: There are some PHP functions that may do what you are wanting to. Try looking at: Some of these functions are slow, so if your database is large, you may have to worry about which ones you use.