Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. feed.php:
  2. header('Access-Control-Allow-Origin: *');
  3.  
  4. $db_name = 'testdb';
  5. $hostname = 'localhost';
  6. $username = 'root';
  7. $password = '';
  8.  
  9.  
  10. $dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
  11.  
  12. $sql = 'SELECT * FROM `test_merchants` WHERE 1 LIMIT 1';
  13. $stmt = $dbh->prepare($sql);
  14. // execute the query
  15. $stmt->execute();
  16.  
  17.  
  18. $result = $stmt->fetchAll( PDO::FETCH_ASSOC );
  19.  
  20.  
  21. $json = json_encode( $result );
  22. echo $json;
  23.  
  24.  
  25. home.ts:
  26.  
  27. import { Component } from '@angular/core';
  28. import { Http } from '@angular/http';
  29. import 'rxjs/add/operator/map';
  30.  
  31. @Component({
  32. selector: 'page-home',
  33. templateUrl: 'home.html'
  34. })
  35. export class HomePage {
  36.  
  37. posts: any;
  38.  
  39. constructor(public http: Http) {
  40. this.posts = null;
  41. this.http.get('http://localhost/feed.php').map(res => res.json()).subscribe(data => {
  42. this.posts = data.id;
  43. console.log(this.posts);
  44. });
  45.  
  46. }
  47.  
  48. }
  49.  
  50.  
  51. when i hit http://localhost/feed.php :
  52. I get:
  53.  
  54. [{"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 "}]
  55.  
  56.  
  57. * Is there any one who can guide that actually what i am missing ...
  58.  
  59. When i printing console log as i have done in home.`enter code here`ts : it simply shows undefined ..
  60.  
  61. enter code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement