mysqli_fetch_array returning only one result

前端 未结 1 1039
忘掉有多难
忘掉有多难 2020-12-07 00:35

I\'m trying to make a very, very simple query of a small mysql database, using the following code (with appropriate values in $host, etc.):

$connection = mys         


        
相关标签:
1条回答
  • 2020-12-07 00:57

    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);
    
    0 讨论(0)
提交回复
热议问题