私は小さな管理パネル用のコードを書いていますが、私はそれほど高度なコーダーではないので、2 つの異なるテーブルを使用して名前を取得する際に問題が発生しています。
これまでの私のコードは次のとおりです。
<?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>
私がやろうとしているのは、2 つのテーブル$tbl_name
と$prtalbe
その unique_id を使用して、ユーザー名を取得することです。したがって、unique_id from$tbl_name
が unique_id from と等しい場合、from$prtable
のユーザー名を表示したいと思います$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
が異なるため、コードに正しく入れたくありませんでした。