Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- feed.php:
- header('Access-Control-Allow-Origin: *');
- $db_name = 'testdb';
- $hostname = 'localhost';
- $username = 'root';
- $password = '';
- $dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
- $sql = 'SELECT * FROM `test_merchants` WHERE 1 LIMIT 1';
- $stmt = $dbh->prepare($sql);
- // execute the query
- $stmt->execute();
- $result = $stmt->fetchAll( PDO::FETCH_ASSOC );
- $json = json_encode( $result );
- echo $json;
- home.ts:
- import { Component } from '@angular/core';
- import { Http } from '@angular/http';
- import 'rxjs/add/operator/map';
- @Component({
- selector: 'page-home',
- templateUrl: 'home.html'
- })
- export class HomePage {
- posts: any;
- constructor(public http: Http) {
- this.posts = null;
- this.http.get('http://localhost/feed.php').map(res => res.json()).subscribe(data => {
- this.posts = data.id;
- console.log(this.posts);
- });
- }
- }
- when i hit http://localhost/feed.php :
- I get:
- [{"user_id":"136","name":"vikas Merchant","phone_number":"+6512345578","rating":"3","shop_name":"vikas shop","shop_location":"{"lat":1.325862,"lng":103.892819}","block_number":"11","postal_code":"408723","street":"Ubi Road 1","unit":"#06-48","shop_phone_number":"+651234566","shop_contact_name":"+6598765432","shop_logo":"1470280789-22431.png","shop_description":"testing shop "}]
- * Is there any one who can guide that actually what i am missing ...
- When i printing console log as i have done in home.`enter code here`ts : it simply shows undefined ..
- enter code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement