PHP空表,但没有错误

时间:2014-08-01 13:44:40

标签: php mysql

我有一个搜索按钮,用于搜索报告输入日期。但是当我点击按钮时,即使我正确输入了开始和结束日期,表格也显示为空。

PHP代码

<?php
include('konek.php');

$start = isset($_GET['d1']) ? $_GET['d1'] : '';
$end = isset($_GET['d2']) ? $_GET['d2'] : '';

if (isset($_GET['submit']) && $_GET['submit']=='Search') {

    $result = mysql_query("SELECT
        t1.qty, t2.lastname, t2.firstname, t2.date, t3.name,
        t2.reservation_id, t2.payable FROM prodinventory AS t1
             INNER JOIN reservation AS t2
             ON t1.confirmation=t2.confirmation
             INNER JOIN products AS t3
             ON t1.room=t3.id
             WHERE t2.date BETWEEN '$start' AND '$end'
             GROUP BY t2.confirmation");

    while ($row = mysql_fetch_array($result)){
        echo'<tr class="record">';
        echo'<td>'; echo $row['reservation_id'];  echo'</td>';
        echo'<td>'; echo $row['date'];  echo'</td>';
        echo'<td>'; echo $row['firstname'].' '.$row['lastname'];  echo'</td>';
        echo'<td>'; echo $row['name'].' '.$row['qty'];  echo'</td>';
        echo'<td>'; echo $row['payable'];  echo'</td>';
        echo'</tr>';

        echo'</tbody>';
        echo'</table>';

        $result1 = mysql_query("SELECT SUM(payable) FROM reservation WHERE date BETWEEN '$d1'    AND '$d2'");
        while ($rows1 = mysql_fetch_array($result1)) {
?>

<div class="pull-right">
    <div class="span">
        <div class="alert alert-info"><i class="icon-credit-card icon-large">    </i>&nbsp;Sub Total: PHP&nbsp;<?php echo number_format(floatval($rows1['SUM(payable)'])); ?  ></div>
    </div>
</div>
</center>
<?php }}} ?>

这是我的HTML表单

<form action="salesreport.php" method="GET">
<input name="submit" id="submit" type="submit" class="btnsearch" value="Search" />
From : <input type="text" name="d1" id="d1" class="tcal" value="" />    
To: <input type="text" name="d2" id="d2" class="tcal" value=""  />

2 个答案:

答案 0 :(得分:0)

<?php echo number_format(floatval($rows1['SUM(payable)'])); ?  >

请检查代码。 PHP的关闭语法&#34;?&#34;和&#34;&gt;&#34;

答案 1 :(得分:0)

您很可能意味着$start$end而不是$d1$d2

$result1 = mysql_query("SELECT SUM(payable) 
                        FROM reservation 
                        WHERE date BETWEEN '$start' AND '$end'");