I am creating an Inline Edit data by using X-editable with PHP Dropdown Select Box. I am facing an issue in that I am not able to create a dynamic select option in jquery from database data.
Actually, I want to echo the source
format of text in PHP so I can add in jquery. The snippet below is in the correct format, but I don't know how to echo that text dynamically using data from PHP.
-- PHP --
$stmt = $connect->prepare("SELECT * FROM `profile`");
$stmt->execute();
-- JQUERY --
$('#employee_data').editable({
container: 'body',
selector: 'td.gender',
title: 'Gender', dataType: 'json',
source: [{value: "Male", text: "Male"}, {value: "Female", text: "Female"}]
});
Please help me to create this json structure [{value: "Male", text: "Male"}, {value: "Female", text: "Female"}]
from a server-side query and pass it into the editable()
function's argument in jquery.
I tried this, but it didn't work:
$result = $stmt->fetchAll();
foreach($result as $data => $value) {
$data = array('value' => $value["category_id"], 'text' => $value["category"]);
}
$category_list = json_encode($data);