0

「製品の詳細」を表示するページを php/html で作成しようとしています。アイコンと「詳細ページ」へのリンクを表示していますが、「詳細ページ」にアイテムが1つしか表示されません。現在、製品のページ (アイコンとリンクがある場所) は「詳細ページ」に問題なくリンクしています。ただし、ページが読み込まれると、「ID」を持つ sql データベース内のすべてのアイテムが読み込まれます。アイテムの 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>';
}
?>
4

1 に答える 1

0
<?php
//This page display a topic
include('admin/variable.php');
include('home.php');

if(isset($_GET['id']))
{
$dn1 = mysql_query('select 
     c.id, 
     c.name, 
     c.description, 
     c.price, 
     c.quantity, 
     c.itemID, 
     c.imgName, 
     c.parent, 
     c.position, 
(select count(c.id) from categories as c where c.parent=c.id) as categories, (select count(c.id) from categories as c where c.parent=c.id and c.id!=0) as replies from categories as c group by c.id order by c.position asc');
if($dn1 === false){
        die(mysql_error());
    }
while($dnn1 = mysql_fetch_array($dn1))
{
$parent = $dnn1['parent'];
  if($_GET['id'] == $parent){ 

?>
<!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="require/style.css" rel="stylesheet" title="Style" />
    <title><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlentities($dnn1['itemID'], ENT_QUOTES, 'UTF-8'); ?> - KB Computers</title>
 </head>
 <body>

  <div class="Content">
<div style="background:white; height:800px;">

<div id="shopNav">
<ul>
    <li class="end"><a href="">Shop</a></li>
            <li><a href="">Catagories</a></li>
            <li><a href="">New Products</a></li>
            <li><a href="">My Account</a></li>
            <li class="end2"><a href="">Checkout</a></li>
        </ul>

    </div>

<div id="thing">
<table><h1><?php echo $dnn1['name']; ?></h1>
<tr>
 <th><?php echo '<img src="image/' . $dnn1['imgName'].'" alt="' . $dnn1['imgName']. '" width="128" height="128"'; ?></th>
</tr>
<tr>
<th><?php echo $dnn1['price']; ?></th>
</tr>
<tr>
<th class="tableDesc"> <?php echo $dnn1['description']; ?></th>
</tr>
    <tr>
        <th><?php echo $dnn1['itemID']; ?></th>
    </tr>
    <?php 
        if(isset($_SEESION['username']) and $_SESSION['username'] == $admin){?>
        <tr>
        <a href="edit_product.php?id=<?php echo $id; ?>&id2=<?php echo $dnn1['itemID']; ?>"><img src="<?php echo $design; ?>/images/edic.png" alt="Edit" /></a>>
        </tr>
    <?php } ?>
    <tr>
        <th> </th>
    </tr>
</table>
</div>
<?php include("require/rightBar.html"); ?></div><?php include("require/footer.html"); 
}
}
}else{echo 'That product doesnt exist!';}
?>

    </div>  
</body>

于 2013-09-15T01:47:45.357 に答える