, JSON display of unnecessary things $ result = $ menu-> show_twoMenu (4 );
$ Col_jobs = array ();
$ I = 0;
While (@ $ row = mysqli_fetch_array ($ result )){
$ Col_jobs [$ I] = $ row;
$ I ++;
}
$ Col_jobs = json_encode ($ col_jobs );
Echo '{"coljobs":'. $ col_jobs .'}';
The output is:
{
"Coljobs ":[
{
"0": "5 ",
"1": "steamed mandarin fish ",
"2": "4 ",
"3": "abc.jpeg ",
"4": "124 ",
"5": "100 ",
"6": "Example ",
"7": "80 ",
"8": "999 ",
"Id": "5 ",
"Name": "steamed mandarin fish ",
"ParentID": "4 ",
"Image": "abc.jpeg ",
"Discount": "124 ",
"Price": "100 ",
"Unit": "Example ",
"Sale": "80 ",
"Stock": "999"
}
]
}
Why?
"0": "5 ",
"1": "steamed mandarin fish ",
"2": "4 ",
"3": "abc.jpeg ",
"4": "124 ",
"5": "100 ",
"6": "Example ",
"7": "80 ",
"8": "999 ",
What should I do if I don't want it?
Reply to discussion (solution)
Mysqli_fetch_array returns a mixture of subscript arrays and associated arrays.
Use mysqli_fetch_assoc as needed to return only the associated array