$result=mysqli_query($con, $sql);
$emparray = array();
// Start looping rows in mysql database.
while($rows=mysqli_fetch_assoc($result)){
$emparray[] = $rows;
// close while loop
}
//print_r($emparray);
//echo json_encode($emparray);
$output = array(
'c2array' => true,
'size' => array(
0 => count($emparray),
1 => 1,
2 => 1
),
'data' => array()
);
$x = 0;
foreach ($emparray as $value) {
$output['data'][$x] = array();
$output['data'][$x][0] = array();
$output['data'][$x][0][0] = $value["nombre"];
$x++;
}
echo json_encode($output);
[/code:2vqhamr3]
Now the array data is correct in the debug layout.
[code:2vqhamr3]{"c2array":true,"size":[7,1,1],"data":[[["test"]],[["Oscar"]],[["Oscar"]],[["test"]],[["test"]],[["oscar"]],[["Oscar"]]]}[/code:2vqhamr3]
But the combobox is showing infinite options. lol
---UPDATE----
I did it!
I fix the combobox like this:
[img="http://s13.postimg.org/is1qrumdz/Sin_t_tulo.png"]
OK now, how can i add an id in the same JSON? i mean i want to get the id of the users from the database, i guess i need them in the JSON query so i have to modify the SQL query to show it on the JSON but i dont know in what format.
Now my JSON looks like this:
[code:2vqhamr3]{"c2array":true,"size":[7,1,1],"data":[["2","test"],["3","Oscar"],["4","Oscar"],["5","test"],["6","test"],["7","oscar"],["8","Oscar"]]}[/code:2vqhamr3]
The number are the id´s of each name in the db, but the c2 array shows only the id of each element but no the name, i want to show the name in the combobox but use the id to work with the mysql db.