title: how to store data as an associative array from mysql database in php
body: <p>I want to achieve to store data as an associative array from mysql database in php but when i just show the result in array form it show me the last inserted result in mysql table. My code:-</p>
  
  <pre><code>public function displayresult(){
      $result = mysql_query('SELECT * FROM user');
      $num = mysql_num_rows($result);
      if(mysql_num_rows($result) &gt; 0){
          for($i=0;$i&lt;=$num;$i++){        
              while($row=mysql_fetch_array($result)){
                  $data[$i]['name']=$row['name'];
                  $data[$i]['contact']=$row['contact'];
              }
          }
      }
      return $data;
  }
  print_r(displayresult());
  </code></pre>
  
  <p>and the result which above code showing is:-</p>
  
  <pre><code> Array
    (
    [0] =&gt; Array
      (
          [name] =&gt; jason
          [contact] =&gt; 4098979774
      )
  
  )
  </code></pre>
  
  <p>It doesn't showing me all results and just only the last inserted result. Please help.  </p>