2
Hello! I am trying to pull data from an API I made in PHP to send in JSON to another site. I managed to pull the result of a whole table of employees, but now I want when click on the employees appear the other data related to it as Phone, address... pulling for his ID.
The API that connects index.html
<?php
require_once 'bd2.php';
header('Access-Control-Allow-Origin:*');
$pdo = conectar();
$listar = $pdo->query("select * from funcionarios");
echo json_encode($listar->fetchAll(PDO::FETCH_OBJ));
?>
The javascript that makes the JSON of index.html
$(document).ready(function(){
var container = $("#teste2");
var lista = container.find("#lista");
var html = '';
$.getJSON('http://teste.com/api-home.php', function(data){
$.each(data, function(k, v){
html += '<p>Nome: '+v.nome+'</p>';
html += '<p>E-mail: '+v.email+'</p>';
html += '<a href="perfil.html?id='+v.id+'">Perfil</a>'
});
lista.html(html);
});
});
The profile API that connects to the profile.html
<?php
require_once 'bd2.php';
header('Access-Control-Allow-Origin:*');
$pdo = conectar();
$id = $_GET['id'];
$listar = $pdo->query("select * from funcionarios where id='$id'");
echo json_encode($listar->fetchAll(PDO::FETCH_OBJ));
?>
The javascript that makes the JSON of the.html profile
$(document).ready(function(){
var container = $("#teste5");
var lista = container.find("#lista2");
var html = '';
$.getJSON('http://teste.com/api-perfil.php', function(data){
$.each(data, function(k, v){
html += '<p>Telefone: '+v.telefone+'</p>';
html += '<p>Endereço: '+v.endereco+'</p>';
});
lista.html(html);
});
});
If you wear it like that:
$listar->fetchAll(3)
? What happens?– adventistaam