如何在mysql查询中使用dropdown值?

时间:2016-06-20 06:47:09

标签: php jquery html mysql ajax

我正在创建一个模块,因为我创建了一个链接,它将以表格的形式显示数据库。我在顶部放了一个选择选项,它将选择数据库表中存在的一列的名称。一旦用户从下拉列表中单击了离开类型并单击显示数据库的链接,它将显示仅包含指定离开类型的过滤表。现在它显示所有leave_types。 感谢帮助。 下面是我的代码和截图。

<select id="subject34" name="subject" class="span3">
<option   value="na" selected="">Choose One:</option>
<option   value="Vacation Leave">Vacation Leave</option>
<option   value="sick Leave">Sick Leave</option>
<option   value="Child Care Leave">Child Care Leave</option>
</select>




<div id="test7766" style="overflow:scroll; height:200px; width:100%;                                     display:none">
<?php

$query = "
SELECT t1.emp_id
     , t1.leave_from
     , t1.leave_to
     , t1.leave_reason
     , t1.leave_requested_date
     , t1.count_day
     , t2.leave_type
     , t3.emp_name 
  FROM pro_emp_leave_dtl as t1
  LEFT 
  JOIN pro_emp_leave_component as t2 
    ON t1.emp_id = t2.emp_id
  LEFT 
  JOIN pro_emp_mst as t3
    ON t2.emp_id = t3.emp_id
 WHERE t1.employee_orignal_id = '".$_SESSION['ADMIN_GAME_ID']."'
";
$result = mysql_query($query);

echo "<table>"; // start a table tag in the HTML

echo "<tr>";
echo "<td><b>Emp Id</h4></b>";
echo "<td><b>Emp Name</b></td>";
echo "<td><b>Leave Reason</b></td>";
echo "<td><b>Leave Type</b></td>";
echo "<td><b>Leave Date</b></td>";
echo "<td><b>Count Day</b></td>";
echo "<td><b>Leave From</b></td>";
echo "<td><b>Leave To</b></td>";
echo "</tr>";

while($row = mysql_fetch_array($result)) {

   // Write the value of the column FirstName (which is now in the array         $row)
  echo "<tr>";
  echo "<td>" . $row['emp_id'] . "</td>";
  echo "<td>" . $row['emp_name'] . "</td>";
  echo "<td>" . $row['leave_reason'] . "</td>";
  echo "<td>" . $row['leave_type'] . "</td>";
  echo "<td>" . $row['leave_requested_date'] . "</td>";
  echo "<td>" . $row['count_day'] . "</td>";
  echo "<td>" . $row['leave_from'] . "</td>";
  echo "<td>" . $row['leave_to'] . "</td>";
  echo"</tr>";

  }


// Close the database connection
mysql_close();

echo "</table>";
?>
</div>

截图: screenshot 1

screenshot 2

0 个答案:

没有答案