<?php
$username = "trainerapp";
$password = "password";
$hostname = "localhost";
$link = @mysql_connect($hostname, $username, $password);
if (@mysql_select_db("trainer_registration")) {
$select_query_num = @mysql_query("select id from program_details");
$num_rows = @mysql_num_rows($select_query_num);
while ($row = @mysql_fetch_assoc($select_query_num)) {
$j = $row['id'];
$select_query = @mysql_query("select id,program_name,company,date_prog from program_details where id = $j");
$fetch_query = @mysql_fetch_assoc($select_query);
$id = $fetch_query['id'];
$pgmname = $fetch_query['program_name'];
$comp = $fetch_query['company'];
$datephp = $fetch_query['date_prog'];
$arr[] = array(
$id,
$pgmname,
$comp,
$datephp
);
}
echo json_encode($arr);
}
?>
CURRENT OUTPUT:
[["1","Sample","Apple","2015-05-27"],["2","Sample 2","Lenovo","2015-05-28"],["14","3","3","09-29-2015"]]
I don't understand this output.
Questions:
What does json_encode actually return? A string of all values or an array separated by ','? Because when I tried str.length() in js file, it returned 126
How do I get output like single rows
["1","Sample","Apple","2015-05-27"] ["2","Sample 2","Lenovo","2015-05-28"] ["14","3","3","09-29-2015"]
in an array in javascript because I need to insert them in html under separate columns. That is, 1,2,14 under the column "ID", sample, sample 2, 3 under the column "Program name", and so on. Please help on parsing this array.