searching

admin

Administrator
Staff member
In the current setup of my code below, both first name and last name must be filled in to get results. I guess I'm trying to get it to meet exact criteria all the time. If first and last name are put into search on the results exactly matching are returned. My goal is to have it so if just first name is entered then everyone that matches the first name are returned. I also must keep in mind that first and last are just 2 possible fields for searching.

Is this realistic what I'm trying to get at here?

example: search on john doe will return;

john doe

NOT

john smith or jane doe

example: search on john will return;

john doe
john smith
etc.

example: search on "john" for first name and "McDonalds" for company will return;

all john's that work at mcdonalds

Thanks,

chuckie





<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript"><!-- //
if (navigator.appVersion.indexOf("Win") == -1) {
document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF=http://www.phpbuilder.com/board/archive/index.php/"stylesheets/interactive_mac.css" TITLE="Imac">');
}else{
document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF=http://www.phpbuilder.com/board/archive/index.php/"stylesheets/interactive_win.css" TITLE="Iwin">');
}
//-->
</SCRIPT><LINK rel="stylesheet" href=http://www.phpbuilder.com/board/archive/index.php/"stylesheets/cross_sheet.css">
</head>

<body>

<?php

$db = mysql_connect("pittweb");

mysql_select_db("mylan",$db);

if ($submit) {

if(isset($last_name)){
$sql = "SELECT * FROM members WHERE ";
if(isset($first_name))
{
$sql .= "first_name ='$first_name' AND last_name = '$last_name'";
}
else
{
$sql .= "last_name = '$last_name'";
}
$result = mysql_query($sql);
}
else
{
echo "Bad search criteria.";
}

$results = mysql_query($query, $db);





while ($myrow = mysql_fetch_array($result)) {

printf("<Table border=1 cellpadding=2><TR><TD width=75 class=\"sans\"><b>%s</b>\n</td><TD width=105 class=\"sans\"><b>%s</b>\n</td><td width=275 class=\"sans\">%s</td><td width=75 class=\"sans\"><a href=http://www.phpbuilder.com/board/archive/index.php/\"http://pitt-mylan-ir/edit_member.php3?member_id=%s\">EDIT</a>\n</td><td width=75 class=\"sans\"><a href=\"http://pitt-mylan-ir/confirm_delete.php3?member_id=%s\">DELETE</a>\n</td></tr></table>", $myrow["first_name"], $myrow["last_name"], $myrow["company"], $myrow["member_id"],$myrow["member_id"]);


}

}



?>
<br>
<a href="query.php3">Return to Search</a>

</body>
 
Back
Top