mini proget angular and php: newsfeed manager.

if you want help, please contact us in our email:
mouhamed_ali_derwich@webi4u.com
if you want help, please contact us in our email:
mouhamed_ali_derwich@webi4u.com

display users listview:

This component is simple, it is responsible for displaying the list of users

So we'll do this following uses case:

  • get list of users from php server.
  • develop webserver php for list of users.

1. get list of users from php server:

copy this code in [relation.component.ts]:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-relation',
  templateUrl: './relation.component.html',
  styleUrls: ['./relation.component.css']
})
export class RelationComponent implements OnInit {
  lstUser: any;
  constructor(private http: HttpClient) { }

  ngOnInit() {

  	this.http.get("http://127.0.0.1/newsfeed_php_project/get_all_user.php")
            .subscribe(response => {
            	  this.lstUser = response;             
            });
  }

}
                    

2. develop webserver php for list of users:

now, we get to develop our php webservice form list view of users. Then copy this code in [get_all_user.php]

<?php

header("Access-Control-Allow-Origin: *");
header("Content-type:application/json");

$servername = "localhost";
$username_db = "root";
$password_db = "root";

$token = $_POST['token'];

try{
    $conn = new PDO("mysql:host=$servername;dbname=newsfeed", $username_db, $password_db);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM user";
    $user = $conn->prepare($sql);
    $user->execute();
    echo json_encode($user->fetchAll());
} catch (Exception $ex) {
    
}