我正在尝试从数据库中获取数据,并在一个页面上显示->网站名称-订单数量-
$query = $this->db->query('SELECT * FROM ebay_orders WHERE order_status="Unshipped" ORDER BY webname');
$this->db->where('userid',$userid);
foreach ($query->result_array() as $row)
{
echo '<div style="padding: 0px 10px 0 2px;">';
echo $row['webname'];
echo ' - ';
echo $query->num_rows();
echo '</div><br>';
}
它的工作,但重复和显示总额像这样-
ebay1 - 20
ebay1 - 20
ebay1 - 20
ebay1 - 20
ebay2 - 20
ebay2 - 20
ebay2 - 20
ebay3 - 20
ebay3 - 20
ebay3 - 20
我想要一个简单的方法来显示这样的数据-
ebay1 - 5
ebay2 - 10
ebay3 - 5
请帮忙!
使用下面的查询
$query = $this->db->query('SELECT *, count(id) as total FROM ebay_orders
WHERE order_status="Unshipped"
GROUP BY webname
ORDER BY webname');
$this->db->where('userid',$userid);
foreach ($query->result_array() as $row)
{
echo '<div style="padding: 0px 10px 0 2px;">';
echo $row['webname'];
echo ' - ';
echo $row['total'];
echo '</div><br>';
}