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:-
public function displayresult(){
$result = mysql_query('SELECT * FROM user');
$num = mysql_num_rows($result);
if(mysql_num_rows($result) > 0){
for($i=0;$i<=$num;$i++){
while($row=mysql_fetch_array($result)){
$data[$i]['name']=$row['name'];
$data[$i]['contact']=$row['contact'];
}
}
}
return $data;
}
print_r(displayresult());
and the result which above code showing is:-
Array
(
[0] => Array
(
[name] => jason
[contact] => 4098979774
)
)
It doesn't showing me all results and just only the last inserted result. Please help.