title: if else condition is not run properlly
body: <p>This is my code and I am unable to run my simple condition. I have used all the ways but it's not working. As I wanted that if count is available then show count and if not then echo 0 in . I know it is simple but I am stuck on it.</p>
  
  <pre><code>&lt;?php
  $hostname = "localhost";
  $username = "root";
  $password = "";
  $db = "usman";
  
  $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
  $result = $dbh-&gt;query(
      "SELECT COUNT(*) as cnt
          FROM ams
          where empid= {$_SESSION['sess_user_id']}
          GROUP BY leavetype
          HAVING leavetype = 'Annual'"
  );
  
  if (!$result) {
      echo "&lt;td&gt;";
      echo 0;
      echo "&lt;/td&gt;";
  } else {
      foreach ($result as $row) {
          echo "&lt;td&gt;" . $row['cnt'] . "&lt;/td&gt;";
          echo "&lt;br&gt;";
      }
  }
  ?&gt;
  </code></pre>