简体   繁体   中英

Display name instead ID from another table

I'm facing a problem to display a name on a table, only the id is displayed I have tried some inner join queries without luck i got 2 tables

Table 1 = empresas

Here is where all the data lives:

例子1

the number 9 in u_tip corresponds to the ID of the data that is in tipoempresas table

Table 2 = tipoempresas

例子2

I want to display the name of the type not the ID

I'm using this code to display the data in a html table

$result = mysqli_query($conn,"SELECT * FROM empresas");


$i = 0;
while($row = $result->fetch_assoc())
{
echo "<tr>";
foreach ($row as $value) {
  echo "<td>" . $value . "</td>";
}
echo "</tr>";

You are already there you just need to use join statement and specify the column you want to display

$result = mysqli_query($conn,"SELECT * FROM empresas AS e INNER JOIN tipoempresas AS t ON t.id = e.u_tip");


$i = 0;
while($row = $result->fetch_assoc())
{
echo "<tr>";
foreach ($row as $value) {
 echo "<td>" . $value['Nombre'] . "</td>"; //SPECIFY THE COLUMN YOU WANT TO DISPLAY
}
echo "</tr>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM