php - I wrote a code to show the availability of doctors according to the date, but when the field on mysql is empty i have this array error -


this code i'm talking about

session_start();  include ('configg.php');  $query = "select date, time gp_appointment name = '$_post[doctor]' , date = '$_post[date]'";  $result = mysql_query($query);     $data = array();    while($row = mysql_fetch_assoc($result))   {      $data[] = $row;    }   $colnames = array_keys(reset($data))    ?>   <table border="1">  <tr>     <?php         //print header        foreach((array)$colnames $colname)        {           echo "<th>$colname</th>";        }      ?>  </tr>      <?php         //print rows        foreach((array)$data $row)        {           echo "<tr>";           foreach($colnames $colname)           {              echo "<td>".$row[$colname]."</td>";           }           echo "</tr>";        }       ?>  </table>  <a href="homepage.php">go homepage</a><br>  <a href="docname.php">check doctor</a><br> 

when chose date exist in databse works fine, if choose date not-existent recieve error:

warning: array_keys() expects parameter 1 array, boolean given in h:\project\xampplite\htdocs\example\phptutorial\doctorav.php on line 15

somebody know do?

check if data perform operation. or print message no records found.

if((!empty($data)){      // perform operation } else{    echo "no records found"; } 

note: please, don't use mysql_* functions in new code. no longer maintained and officially deprecated. see red box? learn prepared statements instead, , use pdo or mysqli - this article decide which. if choose pdo, here tutorial.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -