I've got this error
Warning: mysqli_fetch_array() [function.mysqli-fetch-array]: Couldn't fetch mysqli_result in /home/fights7/public_html/include/load_more_home_posts.php on line 12
And would like to know what I've done wrong with the below code?
$articles_data = mysqli_query($mysqli,"SELECT * FROM streamdata WHERE streamitem_id < '$lastID' ORDER BY streamitem_id DESC LIMIT 10") or die(mysql_error());
while($articles_info = mysqli_fetch_array($articles_data)) {
$json = array();
$json['streamitem_id'] = $articles_info['streamitem_id'];
$json['streamitem_content'] = $articles_info['streamitem_content'];
$json['streamitem_timestamp'] = $articles_info['streamitem_timestamp'];
mysqli_free_result($articles_data);
Straight away, it appears that you are calling
mysqli_free_result()
inside your fetch loop, so after the first loop iteration, your result resource has been closed and freed, and no more results will be available.I note that you're calling
mysqli_fetch_array()
without specifyingMYSQLI_ASSOC
, and so you're getting both numeric and associative keys back. If you are using everything in your JSON, you don't need to do all those assignments if you useMYSQLI_ASSOC
ormysqli_fetch_assoc()
: