Помогите собрать выборку

 

<?php 
include ("blocks/db.php")/*соендиняемся с БД*/
?>
<?php
if (isset($_POST['ferstname'])) {$ferstname = $_POST['ferstname']; if ($ferstname == '') {unset($ferstname);}}
if (isset($_POST['name'])) {$name = $_POST['name']; if ($name == '') {unset($name);}}
if (isset($_POST['lastname'])) {$lastname = $_POST['lastname']; if ($lastname == '') {unset($lastname);}}
if (isset($_POST['modelauto'])) {$modelauto = $_POST['modelauto']; if ($modelauto == '') {unset($modelauto);}}
if (isset($_POST['VINcode'])) {$VINcode = $_POST['VINcode']; if ($VINcode == '') {unset($VINcode);}}
if (isset($_POST['domicile'])) {$domicile = $_POST['domicile']; if ($domicile == '') {unset($domicile);}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Соединяемся с БД</title>
</head>

<body>
  <td align="center" valign="top">
  <table width="100%" border="1" cellpadding="0" cellspacing="0">
  <tr>
  <th width='40px' scope="col">номер</th>
  <th width='115px' scope="col">Фамилия</th>
  <th width='115px' scope="col">Имя</th>
  <th width='115px' scope="col">Отчество</th>
  <th width='60px' scope="col">Модель авто</th>
  <th width='100px' scope="col"><p>VIN код</p></th>
  <th width='120px' scope="col">Место жительства</th>
  </tr>
  </table>
  <?php 
 
$result = mysql_query("SELECT id, ferstname, name, lastname, modelauto, VINcode, domicile FROM Pokupateli WHERE ferstname LIKE '%$ferstname%' OR name LIKE '%$name%' OR lastname LIKE '%$lastname%' OR modelauto LIKE '%$modelauto%' OR VINcode LIKE '%$VINcode%' OR domicile LIKE '%$domicile%'",$db);
$myrow = mysql_fetch_array($result);  
do  
{
printf ("<table border='1' cellpadding='0' cellspacing='0' class='read'>
  <tr>
  <td width='40px'>%s</td>
  <td width='115px'>%s</td>
  <td width='115px'>%s</td>
  <td width='115px'>%s</td>
  <td width='60px'>%s</td>
  <td width='100px'>%s</td>
  <td width='120px'>%s</td>
   
  </tr>
  </table>", $myrow['id'],$myrow['ferstname'],$myrow['name'],$myrow['lastname'],$myrow['modelauto'],$myrow['VINcode'],$myrow['domicile']);
  }while ($myrow = mysql_fetch_array ($result));
   
 ?>
  </td>
</body>
</html>

пытаюсь через форму делать выборку клиентов когда ищется одна переменная то все нормально но когда пытаюсь так как в коде то выводит всех клиентов.

Посоветуйте как сделать выборку по нескольким переменным.

 
Боюсь ошибиться, но мне кажется, что это из-за того, что Вы используете оператор LIKE для вин-кодов. Когда вин-кода в запросе нет, ставится 0, а вероятность 0 в каждом вин-коде очень большая.
Я обычно сначала формирую запрос в строку и тут можно ее легко формировать в зависимости от условий, а потом уже ищу результат, типа $result = mysql_query("$str);