title: PHP - How can I foreach an SQL Statement by conditional where
body: <p>I want to know how can I foreach a sql count statement depending on its status. When I tried to echo it, all statuses turned into number 1. I want to put it inside a loop instead of doing the statement five times.</p>
  
  <pre><code>&lt;?php
  $statuses = array("In-process", "Approved", "Draft", "Approved" , "Rejected"); 
  
  foreach ($statuses as $stat) {  
      $stmt = $db-&gt;prepare(
          "SELECT COUNT(status) FROM `m2_exception_requests`
           WHERE created_by= ? and   status = ?"
      ) or die($db-&gt;error);  
  
      $stmt-&gt;bind_param("ss", $user_id , $stat);
      $stmt-&gt;execute();
      $result = $stmt-&gt;store_result(); 
  
      if  ($stat = 'In-process') {
          $Inprocess1 =  $result;
      }
      if  ($stat = 'Approved') {
          $Approved1 =  $result;
      }
      if  ($stat = 'Draft') {
          $Draft1 = $result;
      }      
  }
  </code></pre>