我正在尝试在 php/html 中创建显示“产品详细信息”的页面。我让它显示图标和“详细信息页面”的链接,但它不会在“详细信息页面”上仅显示一项。目前,产品页面(图标和链接所在的位置)将链接到“详细信息页面”就可以了。但是,当页面加载时,它会加载 sql 数据库中具有“ID”的每个项目。我希望它只获取项目的 id 并显示与该项目相关的页面,但是我收到了所有这些的集群......我拥有的代码如下。我目前正在尝试学习 PHP,所以如果我犯了一个错误,那就是一个非常糟糕的错误,比如效率不高的东西。请发布更有效的方法。我正在按照我在学校的教学方式学习它。
<?php
//This page display a topic
include('admin/variable.php');
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
$dn1 = mysql_fetch_array(mysql_query('select c.id, c.name, c.description, c.price, c.quantity, c.itemID, c.imgName, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc'));
if($dn1['id']>0)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
<title><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlentities($dn1['itemID'], ENT_QUOTES, 'UTF-8'); ?> - KB Computers</title>
</head>
<body>
<div class="header">
<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>
</div>
<div class="Content">
<?php
?>
<h1><?php echo $dn1['name']; ?></h1>
<?php
$dn2 = mysql_query('select c.id, c.name, c.description, c.price, c.quantity, c.itemID, c.imgName, c.position, c.position, (select count(t.id) from topics as t where c.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id WHERE c.id = ' . $id .' order by c.position asc');
//////////////////////////////////////////////////////////
while($dnn2 = mysql_fetch_array($dn2)) //This is line 30!
//////////////////////////////////////////////////////////
{
$parent = $dnn2['parent'];
if(isset($_GET['id']))
{
if($_GET['id'] == $parent){
?>
<div id="thing">
<table>
<tr>
<th><?php echo $dnn2['imgName']; ?></th>
</tr>
<br />
<tr>
<th><?php echo $dnn2['price']; ?></th>
</tr>
<br />
<tr>
<th> <?php echo $dnn2['description']; ?></th>
</tr>
<br />
<tr>
<th><?php echo $dnn2['itemID']; ?></th>
</tr>
<?php
if(isset($_SEESION['username']) and $_SESSION['username'] == $admin){?><div class="edit"><a href="edit_product.php?id=<?php echo $id; ?>&id2=<?php echo $dnn2['itemID']; ?>"><img src="<?php echo $design; ?>/images/edic.png" alt="Edit" /></a></div>
<?php } ?>
</table></div>
<?php
}else{echo 'The parent and id values are not the same.';}
}}
?>
</div>
</body>
</html>
<?php
}
else
{
echo '<h2>This topic doesn\'t exisc.</h2>';
}
}
else
{
echo '<h2>The ID of this topic is not defined.</h2>';
}
?>