set_charset("utf8"); if($mysql->connect_errno) { echo "db connection error : " . $mysql->connect_error; exit(); } //default sql query with limit of 50 records if(empty($sql)) { $sql = "SELECT * FROM movieView where rating='PG' ORDER BY title LIMIT 50"; } $results = $mysql->query($sql); if(!$results) { echo "SQL error: ". $mysql->error; exit(); } // Setup -- create $json_array as a variable that will contain array data while($currentrow = $results->fetch_assoc()) { print_r($currentrow); } /* Once you have populated $json_array can test it with echo "
";
    print_r($json_array);
    echo "
"; */ /* Step 2 -- we've been calling it "json", but it is not actually encoded as json yet if a problem, use code below to debug // echo "json error: " . json_last_error_msg() . "
"; // echo / test output json // NOTE: For actual json stand-alone data api needs to be NO output except the final json. i.e. no debug statements, test outputs, etc. */