This is how I build sql data and send back to ajax call:
(...)
$sql = "SELECT id_option FROM options WHERE id_win = '{$id_win}'";
$result = mysqli_query($conn, $sql);
$rows = array();
while ($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}
$data["win_data"] = $rows;
echo json_encode($data);
This is my ajax function to get options for selectpicker from DB:
$.ajax({
type: "POST",
url: ...,
data: ...,
dataType: "json",
success: function(data) {
$("#id_win").selectpicker("val", data.win_data);
// $("#id_win").selectpicker("val", [1,3];
}
});
data.win_data variable should be: [1,3]
but if I do: console.log(JSON.stringify(data.win_data)); I get:
[{"0":"1","id_option":"1"},{"0":"3","id_option":"3"}]
What is the simplest way to get proper format array for selectpicker?