0

I am creating a form to filter the data on my database (Mysql) with queries based on the user's selections.

I am using this code to generate the "data.json" file:

How can I improve the code and check if the array returns empty values? and instead of drawing a chart without bars tells the user to change the selections.

 <?php
   $rows1 = array();
       $rows1['name'] = $varLabel;
       while($rr = mysqli_fetch_array($TableData)) {
       $rows1['data'][] = $rr[$varLabel];
      }

      $rows = array();
      $rows['name'] = "Registros";
      foreach($TableData as $r) {
        settype($r['cnt'], "integer");
        $rows['data'][] = $r['cnt'];

      } 
      $result = array();
      array_push($result,$rows);
      array_push($result,$rows1);

      file_put_contents("data.json", json_encode($result));

?>
Seph1603
  • 99
  • 11

1 Answers1

2

Since your array is created by looping over your database result set which you access using mysqli, Use mysqli_num_rows

if(mysqli_num_rows($TableData)==0)
{
       // no data
}  
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95