如何根据所选教师列出车辆

发布于 2024-08-22 12:25:53 字数 1011 浏览 2 评论 0原文

我有一个列表框,当用户选择教师时显示车辆列表。我只想根据用户选择的教师列出车辆。

<td>No</td>
<td>Registration No</td>

<?php
     $count = 0;
     $db = mysql_connect('localhost','root') 
     or die ("unable to connect");

 mysql_select_db('fyp',$db) or die ("able to select");
 $sql="SELECT * FROM vehicle_record";
  $result = mysql_query($sql) or die ("Query failed!");
 while($row = mysql_fetch_array($result)){
       $count = $count + 1;
?>

<select name="faculty" >
               <option value="" selected>-- Please Select --</option>
               <option>City Campus</option>
               <option>MFI</option>
               <option>BMI</option>
               <option>MSI</option>
               <option>MIAT</option>
               <option>MICET</option>
               <option>MIMET</option>
               <option>RCMP</option>
             </select> 

i have a list box to show the list of vehicle when user select the faculty. i want to list only the vehicle based on the selected faculty by user.

<td>No</td>
<td>Registration No</td>

<?php
     $count = 0;
     $db = mysql_connect('localhost','root') 
     or die ("unable to connect");

 mysql_select_db('fyp',$db) or die ("able to select");
 $sql="SELECT * FROM vehicle_record";
  $result = mysql_query($sql) or die ("Query failed!");
 while($row = mysql_fetch_array($result)){
       $count = $count + 1;
?>

<select name="faculty" >
               <option value="" selected>-- Please Select --</option>
               <option>City Campus</option>
               <option>MFI</option>
               <option>BMI</option>
               <option>MSI</option>
               <option>MIAT</option>
               <option>MICET</option>
               <option>MIMET</option>
               <option>RCMP</option>
             </select> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鱼忆七猫命九 2024-08-29 12:25:53

我无法完全理解您的问题,但我假设您希望在提交表单后选择车辆设施,您将 javascript 用于此目的:

          <select name="faculty" id="faculty">
           <option value="" selected>-- Please Select --</option>
           <option>City Campus</option>
           <option>MFI</option>
           <option>BMI</option>
           <option>MSI</option>
           <option>MIAT</option>
           <option>MICET</option>
           <option>MIMET</option>
           <option>RCMP</option>
         </select>

         <script type="text/javascripot">
          document.getElementById("faculty").value = "<?php echo $_POST['faculty']?>";
         </script>

但是,如果您的意思是如何显示来自数据库的设施,那么您可以像这样:

<select name="faculty" id="faculty">
<?php
  while($row = mysql_fetch_array($result)){
   echo '<option value="'.$row['field_name'].'">'.$row['field_name'].'</option>';
  }
?>
</select>

I could not get your question fully but I assume you want the vehicle facility to be selected after form is submitted, you put javascript to use for that:

          <select name="faculty" id="faculty">
           <option value="" selected>-- Please Select --</option>
           <option>City Campus</option>
           <option>MFI</option>
           <option>BMI</option>
           <option>MSI</option>
           <option>MIAT</option>
           <option>MICET</option>
           <option>MIMET</option>
           <option>RCMP</option>
         </select>

         <script type="text/javascripot">
          document.getElementById("faculty").value = "<?php echo $_POST['faculty']?>";
         </script>

However, if you meant how to show facilities coming from database, then you can go like this:

<select name="faculty" id="faculty">
<?php
  while($row = mysql_fetch_array($result)){
   echo '<option value="'.$row['field_name'].'">'.$row['field_name'].'</option>';
  }
?>
</select>
一杆小烟枪 2024-08-29 12:25:53

我想你有 2 个选择,一个用于教师,一个用于车辆

<select name="faculty" id="faculty" onchange="getVehicles()">
....
</select>


<select name="vehicle" id="vehicle">
</select>

Javascript 代码

function getVechiles()
{                                       
   $.getJSON("getVechiles.php",{faculty: $("select#faculty").val()}, function(j){
   if(j.length>0)
   {

        var options = '';
        for (var i = 0; i < j.length; i++) {
                options += '<option class="' + j[i].langClass + '" value="' + j[i].value + '">' + j[i].text + '</option>';
        }
        $("#vechile").html(options);

    }

    });
}

和 getVechiles.php

    SELECT * FROM TABLE
    while($row = mysql_fetch_array($result)){
      $js="{value:".row['id'].",text:\"".$row["field"]."\"}";
      $rjson[] =  $js;

    }

   if(is_array($rjson))
   {
     echo '[' . implode(',', $rjson) . ']';
   }    

I suppose you have 2 select one for faculty and one for vehicle

<select name="faculty" id="faculty" onchange="getVehicles()">
....
</select>


<select name="vehicle" id="vehicle">
</select>

Javascript Code

function getVechiles()
{                                       
   $.getJSON("getVechiles.php",{faculty: $("select#faculty").val()}, function(j){
   if(j.length>0)
   {

        var options = '';
        for (var i = 0; i < j.length; i++) {
                options += '<option class="' + j[i].langClass + '" value="' + j[i].value + '">' + j[i].text + '</option>';
        }
        $("#vechile").html(options);

    }

    });
}

and getVechiles.php

    SELECT * FROM TABLE
    while($row = mysql_fetch_array($result)){
      $js="{value:".row['id'].",text:\"".$row["field"]."\"}";
      $rjson[] =  $js;

    }

   if(is_array($rjson))
   {
     echo '[' . implode(',', $rjson) . ']';
   }    
笑红尘 2024-08-29 12:25:53
<?php
$count = 0;
$i_faculty = $_POST['ifaculty'];
$db = mysql_connect('localhost','root') or die ("unable to connect");

mysql_select_db('fyp',$db) or die ("able to select");
$sql="SELECT * FROM vehicle_record WHERE faculty ='".$i_faculty."' ";
$result = mysql_query($sql) or die ("Query failed!");
while($row = mysql_fetch_array($result))
{
    $count = $count + 1;
    ?>
    <select name="ifaculty">
       <option value="" selected="selected">-- Select Faculty --</option>
       <option>City Campus</option>
       <option>MFI</option>
       <option>BMI</option>
       <option>MSI</option>
       <option>MIAT</option>
       <option>MICET</option>
       <option>MIMET</option>
       <option>RCMP</option>
    </select>
<?php
$count = 0;
$i_faculty = $_POST['ifaculty'];
$db = mysql_connect('localhost','root') or die ("unable to connect");

mysql_select_db('fyp',$db) or die ("able to select");
$sql="SELECT * FROM vehicle_record WHERE faculty ='".$i_faculty."' ";
$result = mysql_query($sql) or die ("Query failed!");
while($row = mysql_fetch_array($result))
{
    $count = $count + 1;
    ?>
    <select name="ifaculty">
       <option value="" selected="selected">-- Select Faculty --</option>
       <option>City Campus</option>
       <option>MFI</option>
       <option>BMI</option>
       <option>MSI</option>
       <option>MIAT</option>
       <option>MICET</option>
       <option>MIMET</option>
       <option>RCMP</option>
    </select>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文