我正在准备注册从日期到日期的输入...显示用户从日期到日期的输入...我想显示凭证编号,帐单日期,数量,金额(出现在购买账单中)表)和产品名称(在purchaseitem表中显示),我想根据清单编号在同一行上打印产品名称。(为此,我正在使用组concat)...我的问题是所有数据都显示多次..我不知道代码中的错误在哪里..仅对数据进行一次显示就必须对代码进行哪些更改..下面我附加了代码..帮助我
控制器代码:
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("voucherno", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$this->db->select('GROUP_CONCAT(Prdtname)as itemname',false);
$this->db->order_by('vno','asc');
$this->db->group_by('vno,billno');
$this->db->from('purchaseitem');
$query = $this->db->get('')->result_array();
$data ['query']= $query;
查看代码:
<?php $rowcount = 1 ?>
<?php foreach ($query as $row): ?>
<tr>
<td><?=$rowcount;?></td>
<td><?=$row['voucherno'];?></td>
<td><?=$row['date'];?></td>
<td><?=$row['PName'];?></td>
<td><?=$row['sqty'];?></td>
<td><?=$row['billtot'];?></td>
<td><?=$row['itemname'];?></td>
<?php $rowcount +=1?>
<br>
<?php endforeach ?>
</tr>
我认为数据正在打印多次,因为我使用了两个查询但传递了相同的变量$ data。是否有可能在同一视图页面上加载多个查询结果。 >
答案 0 :(得分:1)
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('purchasebill.*,GROUP_CONCAT(parmaster.Prdtname)as itemname');
$this->db->from('purchasebill');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$this->db->order_by('vno','asc');
$this->db->group_by('vno,billno');
$query = $this->db->get()->result_array();
$data ['query']= $query;
答案 1 :(得分:0)
是的,您可以执行不同的查询并将它们分别传递给视图:
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->order_by("voucherno", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query1 = $this->db->get()->result_array();
$this->db->select('GROUP_CONCAT(Prdtname) AS itemname',false);
$this->db->order_by('vno','asc');
$this->db->group_by('vno,billno');
$this->db->from('purchaseitem');
$query2 = $this->db->get()->result_array();
$data['bills']= $query1;
$data['items']= $query2;
$this->load->view('your_view_path', $data);
然后在视图上,您可以访问$bills
和$items
中的数据。我的建议是,您应该四处游玩,并只创建一个查询来获取所有信息。