搜索

首页  >  问答  >  正文

如何显示与其匹配的id相对应的表格数值

因此,在下面的查询中,我通过 order_id 连接两个表并显示 user_orders 表中的所有值。

根据下图,我尝试仅显示与 order_manager 表匹配的 order_Id 行。

        public function getUserOrder(){
            $sql = "SELECT user_orders.order_id, 
                            user_orders.title, user_orders.price, 
                            user_orders.quantity 
                    FROM order_manager 
                        JOIN user_orders ON order_manager.order_id = user_orders.order_id;";
                
            $stmt = $this->connect()->prepare($sql);
            $stmt->execute();
         
                    
            while ($result = $stmt->fetchAll()){
                return $result;
            }
        }

我尝试使用一个 if 语句,该语句似乎可以执行某些操作,但它给出的值与反向订单 ID 不匹配。

<div class="container mt-5">
<?php $artworks = new Artworks(); ?>


    <div class="row">
        <div class="col-lg-12">
        <table class="table table-dark">
      <thead>
        <tr>
            <th scope="col">Order ID</th>
          <th scope="col">Full Name</th>
          <th scope="col">Phone</th>
          <th scope="col">Address</th>
          <th scope="col">Orders</th>
        </tr>
      </thead>
 

    
<?php
    $artworks->getOrder();
    foreach ($artworks->getOrder() as $art) {

        echo "<tbody>
                <tr>
                    <td>$art[order_id]</td>
                    <td> $art[full_name]</td>
                    <td> $art[phone] </td>
                    <td>$art[address]</td>
                  
                    <td>
                        <table class= 'tale text-center table-dark'>
                        <thead>
                            <tr>
                                <th scope='col'>Order ID</th>
                                <th scope='col'>title</th>
                                <th scope='col'>price</th>
                                <th scope='col'>Quantity</th>
                            </tr>
                        <thead>
                        <tbody>
                <tr>";
        $artworks->getUserOrder();
        foreach ($artworks->getUserOrder() as $order) {
            if ($order['order_id'] == $art['order_id']) {

                echo "<td>$order[order_id]</td>";
            }
            echo "
                  <td>$order[title]</td>
                  <td>$order[price]</td>
                  <td>$order[quantity]</td>
                  </tr>";
        }

        echo "
            </tbody>
            </table>
        </td>
    </tr>
    ";
}
?>
      </tbody>
    </table>
    </div>
 </div>
</div>

这是一张图像来帮助解释所需的输出

P粉710478990P粉710478990287 天前399

全部回复(1)我来回复

  • P粉460377540

    P粉4603775402024-02-18 14:23:10

    解决了将 td 项目移动到 if 语句中的问题。我猜这基本上是正确的。

    $artworks->getUserOrder();
    
    foreach($artworks->getUserOrder() as $order)
    {
        if ($order['order_id'] == $art['order_id']) {
            echo "$order[order_id]";
            echo "
            $order[title]
            $order[price]
            $order[quantity]
            
            ";
        }
    }

    回复
    0
  • 取消回复