显示名称而不是MySQL php表中的ID值

时间:2019-12-21 22:13:08

标签: php mysql database

我是MySQL的新手,我试图在我的网站页面上的表格中显示国家名称而不是国家ID(也与“质量”列相同)。看到php输出页面的照片:

enter image description here

这是php编码:

$sql = "SELECT * FROM `dis_insects` ORDER BY genus ASC";
$result = $conn->query($sql);

//display table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Genus</th>
<th>Species</th>
<th>Subspecies</th>
<th>Sex</th>
<th>Size</th>
<th>Quality</th>
<th>Region</th>
<th>Country</th>
<th>Date</th>
</tr>";

   if ($result->num_rows > 0) {
 // output data of each row

 while($row = $result->fetch_assoc()) {
   echo "<tr>";
   echo "<td>". $row["id"] . "</td>";
   echo "<td>". $row["genus"] . "</td>";
   echo "<td>". $row["species"] . "</td>";
   echo "<td>". $row["subspecies"] . "</td>";
   echo "<td>". $row["sex"] . "</td>";
   echo "<td>". $row["size"] . "</td>";
   echo "<td>". $row["condition_id"] . "</td>";
   echo "<td>". $row["region"] . "</td>";
   echo "<td>". $row["country_id"] . "</td>";
   echo "<td>". $row["collected_on"] . "</td>";
   echo "</tr>";
}

因此,我希望country_id显示名称而不是数字ID。 MySQL表country_id的照片:

enter image description here

我简直不敢相信自己能做到这一点,因此,对此提供的任何帮助将不胜感激。

0 个答案:

没有答案