簡體   English   中英

如何在 codeigniter 的單行中顯示相同的 id 數據?

[英]How to show same id data in single row in codeigniter?

public function get_orderProduct($loginuserID) {
    $this->db->select('client_order.*,product.image_gallery,product.name');
    $this->db->from('client_order');
    $this->db->join('product','client_order.productID = product.productID','LEFT');
    $this->db->where('client_order.clientID',$loginuserID);
    $this->db->where('client_order.status',1);
    $this->db->order_by('client_order.id','desc');
    $sql = $this->db->get();
    $result = $sql->result();
    return $result;
}

<?php 
  if(count($result) > 0){
              $i=1;
              foreach($result as $row){
                    $img = explode(",", $row->image_gallery);
  ?>
                    <tr>
                          <td><?php echo $i; ?></td>
                          <td><?php echo $row->orderID; ?></td>
                          <td><?php echo $row->name; ?></td>
                    </tr>
  <?php
              $i++;
              }    
        }else{
  ?>
              <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    No order available!
              </div>
  <?php
        }
  ?>

我有兩個具有相同 orderID 的產品,我想在單行中顯示相同的 orderID 產品。 現在,在這里它顯示在不同的不同行中。 那么,如何在單行中顯示? 請幫我。

謝謝你

為了解決這個問題,您必須創建一個空數組來存儲 orderids。在打印 orderid 之前,您必須使用in_array方法搜索數組,如果 orderid 存在則忽略打印它,否則使用array_push方法打印並將 orderID 推送到數組。

<?php
$ids = array();
$i=1;
foreach($result as $row){
      $img = explode(",", $row->image_gallery);
?>
<tr>
<td><?php echo $i; ?></td>
<td>
<?php 
  if(!in_array($row->orderID,$ids))
  {
     echo $row->orderID;
     array_push($ids,$row->orderID); 
  }
?>
</td>
<td><?php echo $row->name; ?></td>
</tr>
<?php
$i++;
}  
?> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM