-1
I have a table with all the states with a column of STATE ID, and one of the name of the right state. When the registered user goes the state number with his registration, there need to make a query for example if in the user’s registration written that the state id is 10, there is the query of which the state name is with the id number 10 and displays the name
I have the code like this, I haven’t added the schematic I quoted above yet!
$mysql = new mysqli("localhost", "joao", "123", "final");
$query = $mysql->query("SELECT * FROM c_clientes INNER JOIN c_clientes_enderecos ON c_clientes_enderecos.cliente_id = c_clientes.cliente_id;");
while($row = $query->fetch_array()){
echo
"<tr>" . "<td>" . $row['cliente_id']. "</td>" .
"<td>" . utf8_encode($row['cliente_nome']. " " . $row['cliente_sobrenome']). "</td>" .
"<td>" . $row['cliente_nome_mae']. "</td>" .
"<td>" . $row['cliente_email']. "</td>" .
"<td>" . $row['cliente_telefone']. "</td>" .
"<td>" . $row['cliente_celular']. "</td>" .
"<td>" . $row['cliente_cpf']. "</td>" .
"<td>" . $row['cliente_rg']. "</td>" .
"<td>" . $row['cliente_nascimento_mae']. "</td>" .
"<td>" . $row['cliente_status']. "</td>" .
"<td>" . $row['cliente_data_emprego']. "</td>" .
"<td>" . $row['usuario_id']. "</td>" .
"<td>" . $row['cliente_mae_estado_id']. "</td>" .
"<td>" . $row['regiao_id']. "</td>" .
"<td>" . $row['cliente_habilitado_regiao']. "</td>" .
"<td>" . $row['endereco_id']. "</td>" .
"<td>" . $row['endereco_cep']. "</td>" .
"<td>" . utf8_encode($row['endereco_rua']). "</td>" .
"<td>" . $row['endereco_numero']. "</td>" .
"<td>" . $row['endereco_complemento']. "</td>" .
"<td>" . $row['cidade_id']. "</td>" .
"<td>" . $row['estado_id']. "</td>" . //Aqui vem o id quero
//transformar no nome!
"<td>" . $row['c_clientes_enderecos']. "</td>" . "</tr>"
;
}
Clarify your question, related to php? Or the query in the database? Include your code.
– Leandro Angelo
I do not have a code, but it is to replace the ID by the name in the query dai
– João Pedro Morais
And what is the database, name and structure of the tables?
– Leandro Angelo
I have ID 1 for ex, and in the client’s register ta state 1, how do I replace by name
– João Pedro Morais
Structure http://prntscr.com/jawhn2
– João Pedro Morais
If the state name is in another table, you have to do a JOIN
– Sam
http://prntscr.com/jawi9m
– João Pedro Morais
Are already connected
– João Pedro Morais
Possible duplicate of How to do Inner Join in mysql?
– Sam
See the above question you should get.
– Sam
but I need to replace the number by the name
– João Pedro Morais
blz I’ll try! anything notice here if it worked
– João Pedro Morais