While Loop only returns one row from 9000+ records

前端 未结 4 1505
南笙
南笙 2021-01-29 06:05

I had a script for this that worked great in PHP 5.3. New host only supports 5.5 so I\'ve done some modifying. So far, I can only get one row to be returned. I\'ve been agonisin

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 06:45

    You need to have a multi-dimensional array and you have taken a single dimensional array.

    So, every time record comes, it overwrites older one.

    Hence, you are getting the last record only.

    Modify your code to:

    $i=0;
    $row_array = array();
    while ($row = mysqli_fetch_assoc($result)) {
      $row_array[$i]['title'] = $row['title'];
      $row_array[$i]['year'] = $row['year'];
      $row_array[$i]['author'] = $row['author'];
      $row_array[$i]['journal'] = $row['journal'];
      $row_array[$i]['keywords'] = $row['keywords'];
      $row_array[$i]['abstract'] = $row['abstract'];
      $row_array[$i]['url'] = $row['url'];
      ++$i;
    }
    

提交回复
热议问题