我仍然在一个屏幕上显示来自两个不同表格的数据。这些表都包含一个公共字段名称,我想要的只是过滤该字段名称,并能够根据它们共享的字段名称更改和显示该行的详细信息。
这两个表是:
成员和收件人
在成员中,它有一个主键member_id,它是唯一的。然后在收件人中我创建了一个member_id字段,该字段也需要链接到members表的唯一member_id。
以下代码调用成员表
中的信息<?php
$con = mysql_connect("localhost", "****", "****");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stingin_epanic", $con);
$result = mysql_query("SELECT * FROM members WHERE member_msisdn='$slusername'");
echo "<table border='1'>
<tr>
<th>Membership</th>
<th>Number</th>
<th>Registration Date</th>
<th>End Date</th>
<th>Copy of ID</th>
</tr>";
while ($row = mysql_fetch_array($result)) {
echo "<td><center>" . $row['member_id'] . "</td>";
echo "<td><font color=blue>" . $row['member_msisdn'] . "</td>";
echo "<td><center>" . $row['asdate'] . "</td>";
echo "<td><center>" . $row['aedate'] . "</td>";
echo "<td><center>" . $row['attid'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
这很好用,给了我我需要的东西。我也在这里调用member_id来显示主键。
在同一页面上,我尝试使用以下代码从另一个表中调用与该成员相关的信息。请注意,该信息应该链接到第一个代码的member_id
<?php
$con = mysql_connect("localhost", "****", "****");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stingin_epanic", $con);
$result = mysql_query("SELECT * FROM members a INNER JOIN recipients b ON member_id = member_id WHERE member_msisdn=$slusername");
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Number</th>
</tr>";
while ($row = mysql_fetch_array($result)) {
echo "<td><font color=blue>" . $row['recipient_name'] . "</td>";
echo "<td>" . $row['recipient_msisdn'] . "</td>";
echo "</tr>";
echo "<td><font color=blue>" . $row['recipient_name'] . "</td>";
echo "<td>" . $row['recipient_msisdn'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
使用第二个代码我没有得到任何结果,因为它没有调用任何信息
答案 0 :(得分:0)
更改此
"SELECT * FROM members a INNER JOIN recipients b ON member_id = member_id WHERE member_msisdn=$slusername"
在此
"SELECT * FROM members a INNER JOIN recipients b ON a.member_id = b.member_id WHERE member_msisdn=$slusername"
也许这会有所帮助。