Php 如何在codeigniter中的单行中显示相同的id数据? 公共函数get\u orderProduct($loginuserID){ $this->db->select('client\u order.*,product.image\u gallery,product.name'); $this->db->from('client_order'); $this->db->join('product','client_order.productID=product.productID','LEFT'); $this->db->where('client\u order.clientID',$loginuserID); $this->db->where('client\u order.status',1); $this->db->order_by('client_order.id','desc'); $sql=$this->db->get(); $result=$sql->result(); 返回$result; } 没有订单!

Php 如何在codeigniter中的单行中显示相同的id数据? 公共函数get\u orderProduct($loginuserID){ $this->db->select('client\u order.*,product.image\u gallery,product.name'); $this->db->from('client_order'); $this->db->join('product','client_order.productID=product.productID','LEFT'); $this->db->where('client\u order.clientID',$loginuserID); $this->db->where('client\u order.status',1); $this->db->order_by('client_order.id','desc'); $sql=$this->db->get(); $result=$sql->result(); 返回$result; } 没有订单!,php,codeigniter-3,Php,Codeigniter 3,我有两个具有相同orderID的产品,我想在单行中显示相同的orderID产品。现在,它显示在不同的行中。那么,我如何在单行中显示?请帮帮我 谢谢要解决此问题,您必须创建一个空数组来存储orderid。在打印orderid之前,您必须使用\u array方法中的搜索数组,如果orderid存在,请忽略打印,否则使用array\u push方法打印并将orderid推送到数组中 public function get_orderProduct($loginuserID) { $this-&

我有两个具有相同orderID的产品,我想在单行中显示相同的orderID产品。现在,它显示在不同的行中。那么,我如何在单行中显示?请帮帮我


谢谢

要解决此问题,您必须创建一个空数组来存储orderid。在打印orderid之前,您必须使用\u array方法中的
搜索数组,如果orderid存在,请忽略打印,否则使用
array\u push
方法打印并将orderid推送到数组中

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之前,必须使用\u array
方法中的
搜索数组,如果存在orderid,则忽略打印,否则使用
array\u push
方法打印并将orderid推送到数组中

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
        }
  ?>


嗨!是否转储查询结果以查看其输出?我不太擅长SQL,但可能您的请求需要一些
group\u by
,以便您的
选择(…)产品。name
结果将以某种方式与给定订单联系。您好!是否转储查询结果以查看其输出?我不太擅长SQL,但可能您的请求需要一些
group\u by
,以便您的
选择(…)产品。name
结果将以某种方式与给定订单联系。@steave请尝试并反馈。@steave请尝试并反馈。