php PHP - MySQL - JSON wrong JSON format
Go to solution
Solved by Mr_KoKa,
Look, I will explain you step by step what you are doing:
if($is_query_run=mysql_query($query)){ //Here you execute the query while($query_execute=$query_execute=mysql_fetch_assoc($is_query_run)){ //Here you get one row from execution result $rows = array(); //You create array into $rows, what was in $rows before will be wiped $rows[] = $query_execute; // You insert one row you just fetch from result to $rows print json_encode($rows); // You encode $rows (which always has only one element as you wipe it every iteration) } }
So, create array before loop, and encode that array after loop, adding elements to array inside a loop is ok.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now