I have a form that searches and fills, via ajax, the person's name and year of birth (in their respective fields), all from the cpf entered by the user.
It's something like this:
Digite o CPF do usuário ______________ <button>BUSCAR DADOS</button>
NOME _________________________
DATA DE NSACIMENTO __________________
With this, two requests are made as follows:
$('#botao').click(function(){
//BUSCA NOME
$.get('buscar_nome.php?cpf='+$('#cpf').val(),
function(result) {
$('#nome').val(result);
});
//BUSCA DATA DE NASCIMENTO
$.get('buscar_data_nascimento.php?cpf='+$('#cpf').val(),
function(result) {
$('#datanascimento').val(result);
});
PHP pages have the following logic:
search_name.php
$cpf = $_GET['cpf'];
$sq1 = select * from tabela where cpf = '$cpf';
$registro = myslq_fetch_array($sq1);
echo registro['nome'];
search_data_name.php
$cpf = $_GET['cpf'];
$sq1 = select * from tabela where cpf = '$cpf';
$registro = myslq_fetch_array($sq1);
echo registro['datanascimento'];
It works perfectly, however, I would like to optimize the search for this data (name and date of birth) using only one request. I guess I should use Array. How should I proceed?