php - JSON_Encode returns NULL (Array) -


i trying parse jsonresponse in android studio, , realized json_encode returns null. ideas cause this? using php 5.2.x

here php:

<?php     header('content-type: application/json');     $con = mysqli_connect("myhost", "myuser", "mypass", "a5911579_android");      $statement = mysqli_prepare($con, "select * markers    order marker_id");     mysqli_stmt_execute($statement);      $arrrows = array();     $arryitem = array();     $arrrows["success"] = false;     $arryitem["success"] = false;      while($arr = mysqli_stmt_fetch($statement)) {         $arryitem["marker_id"] = $arr["marker_id"];         $arryitem["lat"] = $arr["lat"];         $arryitem["lng"] = $arr["lng"];         $arryitem["snippet"] = $arr["snippet"];         $arrrows[] = $arryitem;     }      echo json_encode($arrrows); ?> 

this response:

{"success":false,"0":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"1":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"2":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"3":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"4":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"5":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"6":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null}}

it returns null both lat, lng, snippet , marker_id, though there values in database (using mysql).

any appreciated!

update: inserted $arr, still getting same result update: using

mysqli_stmt_bind_result($marker_id,$lat,$lng,$snippet);  while(mysqli_stmt_fetch($statement)) { $arrrows[] = compact('marker_id','lat','lng','snippet'); } 

gives error (still null returned):

<br><table border='1' cellpadding='2' bgcolor='#ffffdf' bordercolor='#e8b900' align='center'><tr><td><font face='arial' size='1' color='#000000'><b>php error message</b></font></td></tr></table><br /> <b>warning</b>:  mysqli_stmt_bind_result() expects parameter 1 mysqli_stmt, null given in <b>/home/a5911579/public_html/getauction2.php</b> on line <b>16</b><br /> <br><table border='1' cellpadding='2' bgcolor='#ffffdf' bordercolor='#e8b900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'>     <font face='arial' size='1' color='#000000'>free web hosting</font></a></div></td></tr></table> 

{"success":false,"0":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"1":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"2":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"3":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"4":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"5":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null},"6":{"success":false,"marker_id":null,"lat":null,"lng":null,"snippet":null}}

you have use mysqli_stmt_bind_result(...); binding value in listed variables. can use compact() make array variable name

mysqli_stmt_bind_result($marker_id,$lat,$lng,$snippet);  while(mysqli_stmt_fetch($statement)) {     $arrrows[] = compact('marker_id','lat','lng','snippet'); } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -