I have a search form the results from which is displayed on a page. My problem is the search displays a lot of duplicate customers as well.
Here is the form code:
<form name="form1" method="POST" action="cus_search.php">
<table>
<tr>
<td align="left">
Search using customer id, last name, email, product id: <input type="text" name="search" />
<input type="hidden" name="searching" value="yes" />
</td>
<td align="left">
<input type="submit" name="submit" value="Go!" onclick="validate()"/>
</td>
</tr>
</table>
</form>
And here is the cus_search.php page:
<?php
require 'includes/checklogin.php';
require '../functions/func_cart.php';
require '../includes/db.inc.php';
$srch=mysql_real_escape_string($_POST['search']);
$query = "SELECT DISTINCT *
FROM customers,orders
WHERE customers.customer_id like '$srch' or customers.last_name like '$srch' or customers.email like '$srch' or orders.prod_id like '$srch' and customers.customer_id=orders.customer_id";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$row = mysql_fetch_array($result)
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Admin Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="includes/admin.css">
<body>
<table width="100%" height="209" border="0">
<tr>
<td colspan="2">
<?php include 'includes/header.php'; ?>
</td>
</tr>
<tr>
<td width="14%" valign="top">
<?php include 'menu.htm'; ?>
</td>
<td width="86%">
<table id="main">
<tr>
<td colspan="12"><h1>Customers</h1></td>
</tr>
<tr>
<tr>
<td width="5%"><p>Customer ID</p></td>
<td width="10%"><p>First Name</p></td>
<td width="10%"><p>Last Name</p></td>
<td width="10%"><p>Address</p></td>
<td width="10%"><p>Address 2</p></td>
<td width="5%"><p>City</p></td>
<td width="3%"><p>State</p></td>
<td width="3%"><p>Zip</p></td>
<td width="10%"><p>Country</p></td>
<td width="10%"><p>Phone</p></td>
<td width="14%"><p>Email</p></td>
<td width="10%"><p>User Name</p></td>
</tr>
<?php
if ($num < 1) {
echo '<tr><td colspan="12">There are no customers to display.</td></tr>';
} else {
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><a href="customer_info.php?id=<?php echo $row['customer_id'];?>"><?php echo $row['customer_id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td><?php echo $row['address1']; ?></td>
<td><?php echo $row['address2']; ?></td>
<td><?php echo $row['city']; ?></td>
<td><?php echo $row['state']; ?></td>
<td><?php echo $row['zip']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['username']; ?></td>
</tr>
<?php
} // end while
} // end num
?>
</td>
</tr>
</table>
<p><a href="javascript:history.go(-1)">Back</a></p></td>
</tr>
<tr>
<td colspan="2">
<?php include 'includes/footer.php'; ?>
</td>
</tr>
</table>
</body>
</html>
Anyone see what I'm doing wrong.
Thanks!
Lapax
[ Mod Edit - bpat1434 ] Added syntax highlighters.