There are two select.

echo 'Производитель<select id="man" name="Manuf_Name" class = "man">'; $sql=mysql_query("select * from `manufacturer` "); while($result=mysql_fetch_array($sql)){ print "<option value = $result[Manuf_Name]> $result[Manuf_Name]</option>"; } echo '</select>'; 
And the second

 echo 'Модель <select name="sub_name">'; $sql=mysql_query("select `sub_name` from `mark` where `Manuf_Name` = $manuf"); while($result1=mysql_fetch_array($sql)): print "<option> $result1[sub_name]</option>"; endwhile; echo '</select>'; 

When I choose a Manufacturer, I only need its models. That is, when choosing the Aston martin, I do not need a Mercedes model. thank

    1 answer 1

    We can offer 2 main directions to solve this situation:

    1) with reloading the page: you make a form with a select on the page, post the selected select, check the selected item on the server side and show, respectively, the necessary selection already on the displayed page.

    2) without reloading the page:

    2.1) you write all the values ​​into arrays js, from which you then create selects;

    2.2) use the ajax technology: send the selected value of the select through js to your php script, process and send the answer, and on the page you update the select with this answer.

    Do not forget to connect jQuery to page.php. Also note that both of these files lack initialization of the connection to the database, and possibly something else that is used in your project.

    Those. These files can be taken as a sample and finalized.

    page.php

     echo '<form id="MyForm" action="" method="post">'; echo 'Производитель<select id="man" name="Manuf_Name" class = "man"><option value="-1">- Выберите производителя -</option>'; $sql=mysql_query("select * from `manufacturer` "); while($result=mysql_fetch_array($sql)){ print "<option value = $result[Manuf_Name]> $result[Manuf_Name]</option>"; } echo '</select>'; echo 'Модель <select id="mod" name="sub_name"><option value="-1">- Выберите производителя -</option>'; echo '</select>'; echo '<br><button type="submit">Send</button></form>'; echo ' <script> $("#man").change(function(){ var form = $("form[name=MyForm]"), formData = $(form).serialize(); $.ajax({ url: "select-mod.php", type: "POST", data: ({ manuf: $(this).val() }), dataType: "json", success: function( msg ){ if(msg.success) { $("#mod").html(msg.message); } else { alert(msg.message); } } }); $("form[name=MyForm]").submit(function(){ if ($("#man").val()==-1) { alert("Выберите производителя"); return false; } if ($("#mod").val()==-1) { alert("Выберите модель"); return false; } return true; }); </script> '; 

    select-mod.php

     $data = array( 'success' => false, 'message' => '' ); if (!isset($_POST['manuf'])) { $data['message'] = 'Не передан id производителя'; return json_encode($data); } $sql=mysql_query("select `sub_name` from `mark` where `Manuf_Name` = $_POST[manuf]"); if (mysql_numrows($sql)==0) { $data['message'] = 'Модели не найдены'; return json_encode($data); } $data['success'] = true; while($result1=mysql_fetch_array($sql)): $data['message'] .= "<option> $result1[sub_name]</option>"; endwhile; return json_encode($data);