Hey guys just want to ask how can i run retrieve two queries in one function? Here’s my model function below.
public function getSalesByDateRange(){
//total sales by date range
$from = $this->input->post('datefrom');
$to = $this->input->post('dateto');
$sql = "select product_name,date_format(date_of_sales,'%Y/ %M /%d') as date_of_sales,qty_purchased,subtotal from tbl_product
right join sales_line on tbl_product.product_id = sales_line.fkproduct
right join sales on sales_line.fksales = sales.sales_id
where date_of_sales >= '{$from}' and date_of_sales <= '{$to}'
order by date_of_sales desc";
return $this->db->query($sql);
$subtotal = "select sum(subtotal) as total from sales_line
right join sales on sales_line.fksales = sales.sales_id
where date_of_sales >= '{$from}' and date_of_sales <= '{$to}'";
return $this->db->query($subtotal);
}
Here’s my view code below:
<?php
foreach($product->result_array() as $row){
echo "<tr>";
echo "<td>{$row['product_name']} </td>";
echo "<td>{$row['date_of_sales']}</td>";
echo "<td>{$row['qty_purchased']}</td>";
echo "<td>{$row['subtotal']}</td>";
echo "</tr>";
}
?>
<?php
foreach($product->result_array() as $row){ //wont show the total why?
echo "<tr>";
echo "<td colspan='4'>{$row['total']}</td>";
echo "</tr>";
}
?>
Ive got an error when i tried to get the value of the total from my second query. How can i display the total as well? Please help me.
