mysqli_fetch_array returning only one result

mysqli_fetch_array works by pointers each time it’s called

Imagine the following

$result = mysqli_query($connection, "select university from universities_alpha");
$row = mysqli_fetch_array($result); // this is the first row
$row = mysqli_fetch_array($result); // now it's the second row
$row = mysqli_fetch_array($result); // third row

To actually display the data the way you want it to, I suggest you do the following

$rows = array();
$result = mysqli_query($connection, "select university from universities_alpha");
while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}

print_r($rows);

Leave a Comment