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));

?>
0

1 Answer 1

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
}  
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.