title: Store fields in an array and display in php
body: <p>I have a query which fetch all distinct row. i want to store it to an array and display it back using for each loop. can anyone help me. thanks in advance.</p>
  
  <p>here is my code:</p>
  
  <pre><code>//PREPARE QUERIES
  //distinct effective dates
  $allsched = $this-&gt;prepare("SELECT DISTINCT effective_date,status,in_use FROM `working_sched` WHERE `emp_id` = ? ");
  $allsched-&gt;bind_param('i', $emp_id);
  $allsched-&gt;execute();
  $allsched-&gt;bind_result($distinctdate,$stat,$in_use);
  $allsched-&gt;store_result();
  $numrows = $allsched-&gt;num_rows;
  
  //check if query turned empty!
  if($numrows == 0){
      echo '&lt;div id="error"&gt;Sorry no Working Schedule to be displayed for &lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;';  
  }else{
  //if query returned TRUE
  $effdatedist = array();
  while($allsched-&gt;fetch()){
          $effdatedist[] =  $distinctdate; //store the effective dates in an array
          $effdatedist['stat'] = $stat;
  }
  $allsched-&gt;close();
  }
  </code></pre>
  
  <p>and in my foreach loop i want to display the following</p>
  
  <pre><code>foreach($effdatedist as $a){
      //display here
      date, status, in_use
  }
  </code></pre>