Fórum Dúvida em array com id no banco em php #619313
10/01/2023
0
Abaixo uma parte do código que estou em dúvida,
Eu fiz uma pesquisa em php pra me trazer informações de um sistema de cursos, ai preciso que venha no td abaixo a informação do municipio, só que está vindo a id (numero) dele e não o nome, como faço para vir o nome dele, ja que tenho o banco de dados das ids e nomes de cada municipio....
o banco dos municipios é diferente do atual abaixo (este atual pega o cpf por exemplo)
o outro bd chama "municipios" que contem as colunas "id" e "municipio"
try {
$con = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$con->exec("SET CHARACTER SET utf8");
$sql = "SELECT * FROM `inscricao` WHERE `ins_curso` = 13 AND `ins_situacao` = 1 ORDER BY `ins_nome` ASC";
$result = $con->query($sql);
$html_table = '
<table id="myTable" class="table table-sm table-responsive">
<thead>
<tr>
<th style="font-size:15px;text-align:center;">CPF</th>
<th style="font-size:15px;text-align:center;">Municipio</th>
</tr>
</thead>';
foreach($result as $row) {
$html_table .= '
<tr>
<td style="font-size:15px;">' .$row['ins_cpf']. '</td>
<td style="font-size:15px;">' .$row['ins_municipio']. '</td>
</td>
</tr>';Jim
Curtir tópico
+ 0Post mais votado
10/01/2023
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx"
crossorigin="anonymous">
<?php
try {
$con = new PDO("mysql:host=localhost;dbname=astudy","root","");
$con->exec("SET CHARACTER SET utf8");
$sql = "SELECT * FROM inscricao
JOIN municipio on inscricao.ins_municipio = municipio.ins_municipio
WHERE ins_curso = 13 AND ins_situacao = 1 ORDER BY ins_nome ASC";
$result = $con->query($sql);
$html_table = "
<table id='myTable' class='table table-sm table-responsive'>
<thead>
<tr>
<th style='font-size:15px;text-align:left;'>CPF</th>
<th style='font-size:15px;text-align:left;'>Municipio</th>
</thead>";
foreach($result as $row) {
$html_table .= "
<tr>
<td style='font-size:15px;'>" .$row['ins_cpf']. "</td>
<td style='font-size:15px;'>" .$row['nome_municipio']. "</td>
</td></tr>";}
$html_table .= "</table></div>";
echo "<div class='w-50 m-auto'>$html_table</div>";
}
catch (exception $e){echo "problema erro $e";}
Frank Hosaka
Gostei + 1
Mais Posts
10/01/2023
Frank Hosaka
<?php
try {
$con = new PDO("mysql:host=localhost;dbname=astudy","root","");
$con->exec("SET CHARACTER SET utf8");
$sql = "SELECT * FROM inscricao
JOIN municipio on inscricao.ins_municipio = municipio.ins_municipio
WHERE ins_curso = 13 AND ins_situacao = 1 ORDER BY ins_nome ASC";
$result = $con->query($sql);
$html_table = "
<table id=''myTable'' class=''table table-sm table-responsive''>
<thead>
<tr>
<th style=''font-size:15px;text-align:center;''>CPF</th>
<th style=''font-size:15px;text-align:center;''>Municipio</th>
</thead>";
foreach($result as $row) {
$html_table .= "
<tr>
<td style=''font-size:15px;''>" .$row[''ins_cpf'']. "</td>
<td style=''font-size:15px;''>" .$row[''nome_municipio'']. "</td>
</td></tr>";}
echo $html_table;
}
catch (exception $e){echo "problema erro $e";}
Gostei + 0
11/01/2023
Jim
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)