I want to show data from database in the select-option (drop down) in my form
This is HTML code
<select ng-init="get_position()" class="form-control">
<option ng-repeat="position in positionItems" value="">{{position.position_name}}</option>
</select>
This is controller (Angular)
$scope.get_position = function () {
$http.get("/pooh/action.php?action=get_position").success(function (data) {
$scope.positionItems = data;
console.log("GET POSITION!!!");
});
}
and this is PHP
/** Function to Get Staff Position **/
function get_position() {
$qry = mysql_query('SELECT * FROM `position`');
$data = array();
while ($rows = mysql_fetch_array($qry)) {
$data[] = array(
"position_name" => $rows['name']
);
}
print_r(json_encode($data));
return json_encode($data);
}
I understand that the mistake might be from the html code. How to binds controller to form in angular syntax?
?action=get_position
will not call your php function unless you have some logic in your script to grab the $_GET
variable, and even then, you still need to call your function.
Remove that, and call your function in the php script.
function get_position() {
$qry = mysql_query('SELECT * FROM `position`');
$data = array();
while($rows = mysql_fetch_array($qry))
{
$data[] = array(
"position_name" => $rows['name']
);
}
print_r(json_encode($data));
return json_encode($data);
}
// call your function
get_position();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.