我一直在阅读并寻找解决当前问题的解决方案,但没有运气。我目前有一个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>
答案 0 :(得分:0)
我认为您必须在提交第一个表单后将$_POST['date']
值转换为正确的格式,因为您已将mysql格式转换为%b %Y
您是否打印过查询并直接在mysql客户端或phpmyadmin中执行?