I'm trying to perform a Mysql query to calculate the total sales made in a day and save it in an Array that contains all the days of the month and then load it into chartist.js and create a graph.
for ($i = 1; $i <= 31; $i++ )
{
$año = date('Y');
$mes = date('m');
$dia = $i;
$fechaInicio = $año . '-' . $mes . '-' . $dia . ' 00:00:00';
$fechaFin = $año . '-' . $mes . '-' . $dia . ' 23:59:59';
$statement = "SELECT SUM(pr_gadgets_information.cash) as total FROM pr_gadgets_information WHERE pr_gadgets_information.created >= '$fechaInicio' && pr_gadgets_information.created <= '$fechaFin'";
$query = $this->db->query($statement);
while ($salida = mysqli_fetch_object($query))
{
$salida[] = $salida;
}
return $salida;
}
But I receive the following error: Message: mysqli_fetch_object () expects parameter 1 to be mysqli_result, object given
Any suggestions of where the failure comes from? I am using Codeigniter
I just made the following change:
for ($i = 1; $i <= 31; $i++ )
{
$año = date('Y');
$mes = date('m');
$dia = $i;
$fechaInicio = $año . '-' . $mes . '-' . $dia . ' 00:00:00';
$fechaFin = $año . '-' . $mes . '-' . $dia . ' 23:59:59';
$statement = "SELECT SUM(pr_gadgets_information.cash) as total FROM pr_gadgets_information WHERE pr_gadgets_information.created >= '$fechaInicio' && pr_gadgets_information.created <= '$fechaFin'";
$query = $this->db->query($statement);
foreach ($query->result_array() as $row)
{
if($row['total'] == null)
{
$resultado[] = 0;
}else {
$resultado[] = $row['total'];
}
}
}
//var_dump($resultado);
return $resultado;
Performing var_dump ($ row); I get the answers I'm looking for and I also manage the columns that are null, changing them to 0, but when I try to show the data with the return $ result I get the following error: Message: Call to a member function function () on array