Undefined index: message_total this error is occuring in php

shruti A
shruti A used Ask the Experts™
on
$sql1="select a.message_total,b.message_sent from 
( SELECT 
batch_id, count(phone) message_total from to_numbers  group by batch_id
 ) a left outer join
  ( SELECT 
batch_id, count(phone) message_sent from message_sent  group by batch_id
   ) b
   on a.batch_id=b.batch_id 
   where a.batch_id=".$max_id."";

$out = '';  

      $result1 = mysqli_query($db, $sql1);
      
      while($row = mysqli_fetch_row($result1))  
      {  
         
        $out .='<table class="table table-bordered"><tr><td width="30%"><label>message_total</label></td><td width="70%">'.$row['message_total'].'</td></tr><tr><td width="30%"><label>message_sent</label></td><td width="70%">'.$row['message_sent'].'</td></tr></table>';  
      }  

Open in new window


the below error is coming

"
\nNotice: Undefined index: message_total in C:\\xampp\\htdocs\\whatsapp_message_sender\\importData.php on line 256
\n
\nNotice: Undefined index: message_sent in C:\\xampp\\htdocs\\whatsapp_message_sender\\importData.php on line 256
\n<table class="table table-bordered"><tr><td width="30%"><label>message_total</label></td><td width="70%"></td></tr><tr><td width="30%"><label>message_sent</label></td><td width="70%"></td></tr></table> success "

please let me know the solution
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vel EousResearch & Development Manager
Commented:
The error is telling you that the index 'message_total' within your $row assoc array does not exist.  Inspect the content of $row to determine what is actually defined.
Fractional CTO
Distinguished Expert 2018
Commented:
If message_total can come back unset (NULL), then be sure to test for this condition first + then skip further processing if you have a row with a NULL message_total value.

Or you can just extend your SELECT to include tests to only return rows with message_total != 0 or != NULL, however you've designed your schema.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Accepting two similar answers.

Posted has stopped posting.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial