我试图编写一个 PHP 代码/脚本,其中应该执行两个“while”函数。我不知道这是否是正确的方法,但我不知道其他任何事情。
这是完整的代码:
<div class="events">
<div class="eventhead">Log</div>
<?
include_once 'dbcon.php';
$sql2 = "SELECT * FROM event_log ORDER BY id ASC LIMIT 10";
$rs2 = mysql_query($sql2);
while($row2 = mysql_fetch_array($rs2)) {
do {
$id = $row2['id'];
$date = $row2['date'];
$user = $row2['user'];
$action = $row2['action'];
$dept = $row2['dept'];
$desc = $row2['desc'];
if ($dept == "Client") {
$dsql = mysql_query("SELECT * AS title FROM clients WHERE cl_name LIKE '%$desc%'");
} else if ($dept == "Device") {
$dsql = mysql_query("SELECT * AS title FROM devices WHERE dev_id LIKE '%$desc%'");
};
$query = mysql_query($dsql) or die (mysql_error());
while($dq = mysql_fetch_array($query)) {
do {
$did = $dq['id'];
$title = $dq['title'];
?>
<p>• <?= $date ?> | User <?= $user ?> <?= $action ?> <?=$dept ?> - <?= $desc ?>.</p><br />
<p><?= $title ?></p>
<? } while($row2 = mysql_fetch_array($rs2)); ?>
<? } while($dq = mysql_fetch_array($query)); ?>
<? } ?>
<? } ?>
</div>
线
<p>• <?= $date ?> | User <?= $user ?> <?= $action ?> <?=$dept ?> - <?= $desc ?>.</p><br />
如果我排除这部分代码,则有效:
if ($dept == "Client") {
$dsql = mysql_query("SELECT * AS title FROM clients WHERE cl_name LIKE '%$desc%'");
} else if ($dept == "Device") {
$dsql = mysql_query("SELECT * AS title FROM devices WHERE dev_id LIKE '%$desc%'");
};
$query = mysql_query($dsql) or die (mysql_error());
while($dq = mysql_fetch_array($query)) {
do {
$did = $dq['id'];
$title = $dq['title'];
我想包含该部分的主要原因是结果应该是一个超链接,该链接指向显示在那里的客户的 ID!
让我这样解释。如果在浏览器中执行此脚本时没有脚本的错误部分,它会返回以下内容:
► 2013-08-29 18:19:19 | 用户演示更改了客户端 - Myclient。
应该检索myclient的数据库 ID并创建超链接“client.php?id=...”。
所以,当运行第二个 while 函数时,问题就出现了,我想......但是如果客户端创建超链接,我还能如何查询另一个 DB 表来获取 ID 和名称?
先感谢您!!