【发布时间】:2015-03-20 06:33:21
【问题描述】:
我在一个表单中有两个选择框。过滤掉从数据库输出的选定值。这是我的代码
html代码
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" style="width:100px; height:30px;">
<input type="date" name="date" id="date_id" style="width:150px; height:30px; margin-top:-29px; margin-bottom:0px; margin-left:0px;">
<select name="value1" style="width:51px; height:30px;margin-left:161px; margin-top:-29px; margin-bottom:0px;">
<option value="asc">ASC</option>
<option value="dsc">DSC</option>
</select>
<select name="value2" style="width:149px; height:30px;margin-left:226px; margin-top:-26px;">
<option value="readytoship">Ready To Ship</option>
<option value="readytodispatch">Ready To Dispatch</option>
</select>
<input type="submit" value="Filter" name="submit" style="margin-left:163px; margin-top:20px; margin-bottom:0px;"/>
</form>
php代码:
<?php
include "db.php";
if(isset($_POST['submit']))
{
if(($_POST['value1'] == 'asc') && ($_POST['value2'] == 'readytoship'))
{
// query to get all Fitzgerald records
$query = "SELECT * FROM purna_orders WHERE shipping_status='readytoship' order by po_created_date asc";
}
elseif(($_POST['value1'] == 'dsc') && ($_POST['value2'] == 'readytoship'))
{
// query to get all Herring records
$query = "SELECT * FROM purna_orders WHERE shipping_status='readytoship' order by po_created_date dsc";
}
elseif(($_POST['value1'] == 'asc') && ($_POST['value2'] == 'readytodispatch'))
{
// query to get all Herring records
$query = "SELECT * FROM purna_orders WHERE shipping_status='readytodispatch' order by po_created_date asc";
}
elseif(($_POST['value1'] == 'dsc') && ($_POST['value2'] == 'readytodispatch'))
{
// query to get all Herring records
$query = "SELECT * FROM purna_orders WHERE shipping_status='readytodispatch' order by po_created_date dsc";
}
else {
// query to get all records
$query = "select * from purna_orders where shipping_status='readytoship' order by po_created_date asc ";
}
$query = "select * from purna_orders where shipping_status='readytoship' order by po_created_date asc ";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows >= 1)
{
echo "<div id='showmenu' class='scroll'>";
echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'>
<tr class='tr_class' bgcolor='white'>
<td align='center' style='font-weight:bold'> Select </td>
<td align='center' style='font-weight:bold'> Order Id </td>
<td align='center' style='font-weight:bold'> Customer Name </td>
<td align='center' style='font-weight:bold'> Price </td>
<td align='center' style='font-weight:bold'> Pincode </td>
<td align='center' style='font-weight:bold'> COD </td>
<td align='center' style='font-weight:bold'> Status </td>
</tr>";
while($row = mysql_fetch_array($result))
{
$po_id = $row['po_id'];
$_SESSION['po_id'] = $po_id;
$is_cod =($row['is_cod'])? 'Yes' : ' ';
echo "<tr height='20' data-order_id='".$row['po_id']."'>
<td align='center'><input type='radio' class='case' name='case' value='1'></td>
<td align='center'>".$row['po_id']."</td>
<td align='center'>".$row['customer_name']."</td>
<td align='center'>".$row['order_value']."</td>
<td align='center'>".$row['bill_to_pincode']."</td>
<td align='center'>".$is_cod."</td>
<td align='center'>".$row['shipping_status']."</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
}
?>
问题是它直接执行 else 部分而不检查条件。
而且我需要默认显示数据库中的所有记录而不点击过滤器。
【问题讨论】:
-
使用 echo var_dump($_POST),检查发布数据,然后继续。
-
您的代码对我有用。它进入正确的状态?
-
为什么要在所有 if else 条件中编写一个额外的查询。那有什么意思吗?我不认为它有任何意义?它会覆盖您在 if else 条件中写入的查询
-
sry 我写错了