NebuJohn Posted August 5, 2013 Share Posted August 5, 2013 I have recived a set of dat from an android device using Json. I have decoded this data into a PHP array. I took each value of the array usinf foreach and placed in a MySQL statement. But its not working. Can any body help me. Given below is my code. $array=$_POST['nuer']; //numbers fetched $jstring = (array)json_decode($array); foreach($jstring as $value ) //loop over values { $four = mb_substr($value, 0,-10); //to get the first chara's $ten = mb_substr($value, -10); // to get the last ten chara $con=mysqli_connect("localhost","app","test","appt"); //connection to the database $result = mysqli_query($con, "SELECT * FROM profile WHERE (mobileno IN '$ten') AND (code IN '$four')"); while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $friend[] = $row[id]; } mysqli_close($con); $result is returning a null value. When i used a user defined array with random value, this code worked perfectly. Thanks in Advance. Quote Link to comment https://forums.phpfreaks.com/topic/280838-problem-with-josn-data/ Share on other sites More sharing options...
requinix Posted August 5, 2013 Share Posted August 5, 2013 $result is returning a null value.Uh, no? It's either a mysqli_result object or false. The object probably isn't in the form you expect it to be. What does print_r($jstring);output? Oh, and $jstring = (array)json_decode($array);Don't do that when json_decode() can give you an array directly. $jstring = json_decode($array, true); Quote Link to comment https://forums.phpfreaks.com/topic/280838-problem-with-josn-data/#findComment-1443509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.