我一直在阅读并为我当前的问题寻找解决方案,但是没有运气。我目前有一个php页面,可以将mysql的日期完美地提取到一个下拉表中,但是选择它会将我带到结果页面,并且什么也不显示。如果有人可以帮助我,我将非常感激。

这是选择代码:

<div class="span6" style="text-align: center">
    <h4 style="text-align: center">Monthly Tax Search</h4>
    <br>
    <table>
        <thead>

        </thead>
    </table>
    <form action="tax-monthly-report.php" method="post">
        <?php

        $query = "select date_format(date,'%b %Y') 'date',SUM(siit.tax_amount) 'tax_amount',st.tax_description 'tax_description'
                  from si_invoices si
                  inner join si_invoice_items sii on si.id = sii.invoice_id
                  inner join si_invoice_item_tax siit on sii.id = siit.invoice_item_id
                  inner join si_tax st ON siit.tax_id = st.tax_id
                  GROUP BY date_format(date,'%b %Y')";

        $result = mysql_query($query) or die (mysql_error());
        echo '<select name="date">';
        while ($row = mysql_fetch_assoc($result)) {
            echo "<option value='" . $row['date'] ."'>" . $row['date'] ."</option>";
        }
        echo '</select>';
        echo '<br><input type="submit" class="btn btn-success" name="SUBMIT" value="Submit" />
              <input type="reset"  class="btn btn-danger" name="RESET" value="Cancel" />';
        ?>
    </form>

</div>




因此,在这里您可以看到,即使它确实具有完整的查询,也只能选择要在另一页上的表中引用的日期,以下是结果页的代码:

<div class="row">
<div class="span6" style="text-align: center">
    <h4 style="text-align: center">Monthly Tax Search</h4>
        <br>
    <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Tax Type</th>
                        <th>Total</th>
                    </tr>
                </thead>
                    <tbody>
<?
$date = $_POST['date'];
$query = "select date_format(date,'%b %Y') 'date',SUM(siit.tax_amount) 'tax_amount',st.tax_description 'tax_description'
      from si_invoices si
      left join si_invoice_items sii on si.id = sii.invoice_id
      left join si_invoice_item_tax siit on sii.id = siit.invoice_item_id
      left join si_tax st ON siit.tax_id = st.tax_id
      WHERE date =  '".mysql_real_escape_string($date)."'
      GROUP BY st.tax_description,date_format(date,'%b %Y')";

        if($num_result == 1) {
        echo '<b>ERROR</b>';
        }

$result =mysql_query($query) or die (mysql_errno());

            while($row = mysql_fetch_assoc($result)) {
                echo '  <tr>
                            <td>' . $row['date'] . '</td>
                            <td>' . $row['tax_description'] . '</td>
                            <td style="text-align: right">'."$ " . number_format($row['tax_amount'],2) . '</td>
                        </tr>';
            }
?>
                  </tbody>
            </table>
</div>

最佳答案

我认为您必须在提交第一个表单后在获取记录时将$_POST['date']值转换为正确的格式,因为您已将mysql格式转换为%b %Y

您是否已通过打印查询进行检查并直接在mysql客户端或phpmyadmin中执行该查询?

关于php - PHP/MySQL下拉列表未在表中显示所选结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18313359/

10-11 05:21
查看更多