Please excuse the messy code, I'm still in early stages.
I have the following code i'm using using with a form to search. Currently I have it set up to search if a last name or first name is entered.
Question: How can I set this up So that if you search on last name only it returns results which match and also if you search on last name and first name it returns the results that match exactly; Not ones that match both last name and first name?
ex. search on john doe; will return
john doe
not---
john smith
anna doe
john doe
<head>
<title>Untitled</title>
</head>
<body>
<?php
$db = mysql_connect("pittweb");
mysql_select_db("mysql",$db);
if ($submit) {
$result = mysql_query("SELECT * FROM members WHERE last_name LIKE '$last_name' OR first_name LIKE '$first_name'",$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"]);
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($member_id) {
// editing so select a record
$sql = "SELECT * FROM members WHERE member_id=$member_id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$member_id = $myrow["member_id"];
$first_name = $myrow["first_name"];
$last_name = $myrow["last_name"];
$address = $myrow["address"];
$city = $myrow["city"];
$company = $myrow["company"];
$faxlist = $myrow["faxlist"];
$state = $myrow["state"];
$zip = $myrow["zip"];
$email = $myrow["email"];
$q = $myrow["q"];
$k = $myrow["k"];
$conference = $myrow["conference"];
$calendar = $myrow["calendar"];
$christmas = $myrow["christmas"];
$pocketcal = $myrow["pocketcal"];
// print the member_id for editing
?>
<input type=hidden name="member_id" value="<?php echo $member_id ?>">
<?php
}
?>
<Table><tr>
<td width=50 class="sans">First:</td><td><input type="Text" name="first_name" value="<?php echo $first_name ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">10K:</td><td><input type="checkbox" name="k" value=<?php echo $k ?> <?php if ($k="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Last:</td><td><input type="Text" name="last_name" value="<?php echo $last_name ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">10Q:</td><td><input type="checkbox" name="q" value=<?php echo $q ?> <?php if ($q="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">company:</td><td><input type="Text" name="company" value="<?php echo $company ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Calendar:</td><td><input type="checkbox" name="calendar" value=<?php echo $calendar ?> <?php if ($calendar="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Address:</td><td><input type="Text" name="address" value="<?php echo $address ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Conference Call:</td><td><input type="checkbox" name="conference" value=<?php echo $conference ?> <?php if ($conference="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">City:</td><td><input type="Text" name="city" value="<?php echo $city ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Faxlist:</td><td><input type="checkbox" name="faxlist" value=<?php echo $faxlist ?> <?php if ($faxlist="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">State:</td><td><input type="Text" name="state" value="<?php echo $state ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Investor Xmas:</td><td><input type="checkbox" name="christmas" value=<?php echo $christmas ?> <?php if ($christmas="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Zip:</td><td><input type="Text" name="zip" value="<?php echo $zip ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Pocket Calendar:</td><td><input type="checkbox" name="pocketcal" value=<?php echo $pocketcal ?> <?php if ($pocketcal="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Email:</td><td><input type="Text" name="email" value="<?php echo $email ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans"> </td><td> </td></tr>
<tr><td width=50 class="sans"> </td><td class="sans"><input type="Submit" name="submit" value="Enter information"></td></tr>
</form>
</table>
</body>
I have the following code i'm using using with a form to search. Currently I have it set up to search if a last name or first name is entered.
Question: How can I set this up So that if you search on last name only it returns results which match and also if you search on last name and first name it returns the results that match exactly; Not ones that match both last name and first name?
ex. search on john doe; will return
john doe
not---
john smith
anna doe
john doe
<head>
<title>Untitled</title>
</head>
<body>
<?php
$db = mysql_connect("pittweb");
mysql_select_db("mysql",$db);
if ($submit) {
$result = mysql_query("SELECT * FROM members WHERE last_name LIKE '$last_name' OR first_name LIKE '$first_name'",$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"]);
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($member_id) {
// editing so select a record
$sql = "SELECT * FROM members WHERE member_id=$member_id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$member_id = $myrow["member_id"];
$first_name = $myrow["first_name"];
$last_name = $myrow["last_name"];
$address = $myrow["address"];
$city = $myrow["city"];
$company = $myrow["company"];
$faxlist = $myrow["faxlist"];
$state = $myrow["state"];
$zip = $myrow["zip"];
$email = $myrow["email"];
$q = $myrow["q"];
$k = $myrow["k"];
$conference = $myrow["conference"];
$calendar = $myrow["calendar"];
$christmas = $myrow["christmas"];
$pocketcal = $myrow["pocketcal"];
// print the member_id for editing
?>
<input type=hidden name="member_id" value="<?php echo $member_id ?>">
<?php
}
?>
<Table><tr>
<td width=50 class="sans">First:</td><td><input type="Text" name="first_name" value="<?php echo $first_name ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">10K:</td><td><input type="checkbox" name="k" value=<?php echo $k ?> <?php if ($k="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Last:</td><td><input type="Text" name="last_name" value="<?php echo $last_name ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">10Q:</td><td><input type="checkbox" name="q" value=<?php echo $q ?> <?php if ($q="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">company:</td><td><input type="Text" name="company" value="<?php echo $company ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Calendar:</td><td><input type="checkbox" name="calendar" value=<?php echo $calendar ?> <?php if ($calendar="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Address:</td><td><input type="Text" name="address" value="<?php echo $address ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Conference Call:</td><td><input type="checkbox" name="conference" value=<?php echo $conference ?> <?php if ($conference="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">City:</td><td><input type="Text" name="city" value="<?php echo $city ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Faxlist:</td><td><input type="checkbox" name="faxlist" value=<?php echo $faxlist ?> <?php if ($faxlist="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">State:</td><td><input type="Text" name="state" value="<?php echo $state ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Investor Xmas:</td><td><input type="checkbox" name="christmas" value=<?php echo $christmas ?> <?php if ($christmas="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Zip:</td><td><input type="Text" name="zip" value="<?php echo $zip ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans">Pocket Calendar:</td><td><input type="checkbox" name="pocketcal" value=<?php echo $pocketcal ?> <?php if ($pocketcal="CHECKED") { echo "CHECKED"; } ?>></td></tr>
<tr><td width=50 class="sans">Email:</td><td><input type="Text" name="email" value="<?php echo $email ?>" size="30"><br></td><td width=50> </td><td width=100 class="sans"> </td><td> </td></tr>
<tr><td width=50 class="sans"> </td><td class="sans"><input type="Submit" name="submit" value="Enter information"></td></tr>
</form>
</table>
</body>