doumei9832 2018-03-01 00:39
浏览 69

显示名称而不是另一个表中的ID

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:

example1

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

Table 2 = tipoempresas

example2

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>";
  • 写回答

1条回答 默认 最新

  • dos8244 2018-03-01 00:43
    关注

    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>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序