我正在为我的小管理面板编写代码,并且由于我不是那么高级的编码器,所以我在使用两个不同的表获取名称时遇到了一些麻烦。
到目前为止,这是我的代码:
<?php
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
include 'db_connect.php';
$sql = "SELECT * FROM $tbl_name WHERE is_dead='0'";
$result=mysql_query($sql);
?>
<title>Title</title>
<center><img src="header.png"></center>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<? include 'menu.php';?>
</tr>
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Unique ID</strong></td>
<td align="center"><strong>Model</strong></td>
<td align="center"><strong>Last Online</strong></td>
<td align="center"><strong>Options</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['id']; ?></td>
<td><? if ($rows['unique_id'] == 7815684) { echo '<font color="blue"><b><u>7815684</u></b></font>'; }
elseif ($rows['unique_id'] == 2312964) { echo '<font color="blue"><b><u>2312964</u></b></font>'; }
else { echo $rows['unique_id']; } ?></td>
<td><? echo $rows['model']; ?></td>
<td align='center'><font color="green"><b><? echo $rows['last_updated']; ?></b></font></td>
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
所以我要做的是获取用户名,使用两个表$tbl_name
并$prtalbe
使用它们的 unique_id。所以,如果 unique_id from$tbl_name
等于 unique_id from $prtable
,我想显示用户名 from $prtalbe
。
我一直在尝试另一个 sql 查询:
$sql = "SELECT * FROM $tbl_name, $prtable WHERE $tbl_name.unique_id = $prtable.unique_id;
$result=mysql_query($sql);
然后做while循环让它工作
while($rows=mysql_fetch_array($result)){
$rows['name'];
}
它确实有效,但它不想将它直接放入我的代码中,因为ID
from$prtable
和$tbl_name
不同。