Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49184

Insert the retrieve data from the database into the select option in .html

$
0
0

@Pajimola wrote:

Hello everyone i'm new to angular js and ionic so i want to ask something :smiley:
I want to put the data i retrieve from my database into my select option in my html.
This is my code in controllers, html, and php. My only problem i how i can display or insert those retrieve data on my select option. Thank you for any help :smiley:
My controller code
.controller('ClassCtrl', function ($scope, $http) {

  var link = 'http://127.0.0.1/mobile/subject.php';
  var userid = JSON.parse(localStorage.getItem('loginDetails'));
  console.log(userid);


  $http.post(link, {userid: userid}).success(function(res){
  console.log(res);
})
.error(function(err) {
  console.log(err)
});

My php code.
<?php
header("Access-Control-Allow-Origin: *");
require_once('connection.php');

$post_data = file_get_contents('php://input');
$request = json_decode($post_data);
//var_dump($post_data);

$userid= $request->userid;

$subject_sql ="SELECT SubjectName FROM subjects WHERE userid = '" .$userid. "' ";
$result = $con->query($subject_sql);

while($re=$result->fetch_assoc())
{
$res_array[] = $re;
}
echo json_encode($res_array);
?>
And here is my html code where i want to put the data i get from my database.






Select Subject







Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49184

Trending Articles