如何从数据库而不是全部获取一个订单?

时间:2015-08-04 05:27:29

标签: php

  1. 我有两个订单超链接发送给客户。
  2. 当客户点击第一个链接时,它应显示费用和订单历史记录。
  3. 我的代码正确显示费用但是提取所有订单。但它应该只显示一个与收费相关的订单。
  4. 这是我的billingHistory.php文件     &#39 ;;

     include 'systemMenu.php';
    echo '<h4>All Charges</h4>';
    
         $user = unserialize($_SESSION['user']); 
      $query = "SELECT * FROM billingItems WHERE  userID='".$user->userID. " '  GROUP BY deliveryTimestamp DESC"; 
                     $result = mysqli_query($db, $query);
    
                     while($row = mysqli_fetch_array($result)){
                      echo '<p>';
    
                        echo '<a href="billingHistory1.php?deliveryTimestamp=' .$row["deliveryTimestamp"]. '">'.
                        ' Order Delivered on' . '</a>' .$row['deliveryTimestamp']  ;
    
                                }
                          echo '</div></body></html>';
    
                         $_SESSION['user'] = serialize($user);
                         include 'footer.html';
                            ?>
    
  5. 这是我的billingHistory1.php

        <?php
         include 'preCode.php';
         include 'header.php';
         echo '<body><div class="standardLayout">';
         include 'systemMenu.php';
          echo '<h2>All Charges</h2>';
    
          $user = unserialize($_SESSION['user']);
    
    
           $query = "SELECT * FROM billingItems WHERE userID='" .$user->userID. "'  AND  DELIVERYTIMESTAMP='" .$_REQUEST["deliveryTimestamp"]. "' ORDER BY deliveryTimestamp DESC"; 
    
            $result = mysqli_query($db, $query);
            while($row = mysqli_fetch_array($result)){
             echo '<p>';
             echo '<p>'.   $row['type'] . '<br>' . 
                'Cost: $' . $row['amount'] . '<br>' .  '</p>' ;
                      }
    
             echo '<h2>Order History</h2>';
    
            $query1 = "SELECT * from Orders WHERE userID = '" . $user->userID . "' AND delivered = '1' GROUP BY ID DESC"; 
            $result1 = mysqli_query($db, $query1);
    
             while ($row1 = mysqli_fetch_array($result1)){
             echo '<p>';
             echo $row1["produce"] . ',' . $row1["meat"] . ',' .   $row1["bakeryBread"] . ',' . $row1["frozen"] . ',' . $row1["dairy"] . ',
               ' . $row1["snacks"] . ',' . $row1["cannedFood"] . '</p>' ;
    
            }
    
           echo '</div></body></html>';
    
           $_SESSION['user'] = serialize($user);
          include 'footer.html';
           ?>
    

    这是我的第一个输出:(订单已送达是超链接)

            All Charges
            Order Delivered on2015-05-16 14:48:17
            Order Delivered on2015-05-16 14:46:21
    

    这是我的第二个输出:(当客户点击订单已交付(超链接)时,它应显示所有费用,并且只显示与费用相关联的一个订单历史记录,而不是显示所有订单历史记录。

              All Charges
               Grocery Cost
               Cost: $2.49
               Shopping & Delivery 
               Cost: $0.00
    
               Order History
               1 Chilli,fish,bread,ice,milk, ,
               2 Tomatoes,,,,, ,
    

1 个答案:

答案 0 :(得分:2)

您需要添加这样的LIMIT:

SELECT * FROM billingItems WHERE  userID='".$user->userID. " '  GROUP BY deliveryTimestamp DESC LIMIT 1

...或扩展您的WHERE子句以限制更多。