I have seen the answer for MYSQL - Select specific value from a fetched array but it is showing an error for me.
It says "Notice: Undefined offset: 1" at the echo line. I can't figure out what have i done wrong.
$qry = "Select Address, Phone from People where name='david'";
mysqli_connect('localhost' , 'root' , '' ,'database');
$result = mysqli_query(mysqli_connect('localhost' , 'root' , '' ,'database'), $qry);
mysqli_close(mysqli_connect('localhost' , 'root' , '' ,'database'));
$row = array();
while( $row[] = mysqli_fetch_array( $result ) );
echo $row[1]['Address'];
echo $row[1]['Phone'];
while()loop is indeed correct, I didn't notice this statement,$row = array();. The problem is, you're closing the connection beforewhile()loop. And there's no need to create a separate connection in each and every places, just create a connection and use the returned handler in the subsequent statements.while()condition. You'll end up adding an extra element to the array containing thefalsevalue when you reach the end of the results. Use the normal idiomwhile ($row = mysqli_fetch_array($result)) { $rows[] = $row; }.