I've been scratching my brain for hours already, first
html part :
<div class="list">
<a class="item item-text-wrap item-thumbnail-left" ng-repeat='x in MainResults' href="#/">
<img data-ng-src="img({{x.ID}})" width="100%">
<font size="2pt">{{x.post_title}}</font><br>
<font size="2pt">{{x.post_date}}</font>
</a>
</div>
AngularJS part :
function GetMainPage() {
$http.get("http://test.web.id/7291001/MainPage.php").
success ( function(data) {
$scope.MainResults = data;
}
);
};
$scope.img = function (NewsID) {
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
var postID = 'ID='+JSON.stringify (ID);
$http({
method : 'POST',
url : 'http://test.code.id/7291001/GetImage.php',
data : postID,
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).success(function(res) {
console.log(res);
}).error(function(error) {
console.log(error);
});
};
The PHP Part :
header("Access-Control-Allow-Origin: *");
$data = json_decode($_POST['ID']);
//echo $data;
//Keperluan Koneksi
$database = "test_db";
$hostname = "test.code.id";
$username = "*****";
$password = "*****";
//Koneksi
$db = new PDO("mysql:host=$hostname;dbname=$database", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
//Query1
$sql1 = "SELECT pict_url FROM wp_posts WHERE post_parent = '$data' AND post_type = 'attachment' AND post_mime_type = 'image/jpeg' ORDER BY post_date ASC LIMIT 0,1";
$prep1 = $db->prepare($sql1);
$prep1->execute();
//Array Result 1
$result1 = $prep1->fetchAll(PDO::FETCH_ASSOC);
//JSON Result 1
$json1 = json_encode($result1);
echo $json1;
$db = null;
What I Actually trying to do is, grabbing pict_url from the ID i've grabbed from MainResults and displayed in my html part, but I Cannot to make it work, can someone help me with this ? The Database Connection is fine, but i cant figure out how angularjs should work.