Naveed Abbas Naveed Abbas - 4 months ago 11
PHP Question

If in a last 7 days one day task not exist how i get zero rather than null.it return undefined offset

SELECT 'task_id',date,'task_name',count('task_id') AS total
FROM tasks


/* Where clause */
where date between ADD_DATE(now(),-7) and now() group by date

/* loop for fetch records */

for($i=0; $i <= $row_date= mysqli_fetch_array($record); $i++)
{
$total_task[$i]=$row_date['total'];

}
/* it return undefined off set on index */
echo $total_task[0];
echo $total_task[1];
echo $total_task[2];
/* up to so on */
/* i want return 0 for all 6 index if task is not exist*/

Answer

I would like to suggest trying something like:

SELECT
task_id,
date,
task_name,
count(task_id) AS total
FROM tasks
WHERE date >= NOW() - INTERVAL 1 WEEK
AND date <= NOW()
Comments