2016-04-24 15 views
2

私は2つのファイルを持っています: productlist.phpには、クリックすることができる詳細ボタンが付いたすべての写真がすべて表示されます。 productdetail.phpには、画像と説明付きの特定の写真の詳細が表示されます。Image //詳細は表示されません

ただし、productlist.phpページの詳細ボタンをクリックすると、productdetail.phpページに進みますが、画像や説明は表示されません。

は以下productlist.phpでコードです:

<?php 
$link = mysql_connect("xxx", "xxx", "xxx"); 
mysql_select_db("xxx"); 

$sql = "SELECT * FROM products order by createdate desc"; 

$result = mysql_query($sql, $link); 
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
    ?> 

    <div class="productlist_content"> 
     <div class="product_list"> 
      <h1><?=$line["name"];?></h1> 
      <img class="product_list_image" 
       src="<?=$line["image"];?>" width="140" height="187"><br><br> 
      <a href="productdetails.php?id=<?=$line["id"];?>"> 
       <img src="images/details.gif" width="60" height="20" border="0"> 
      </a> 
     </div> 
    </div> 
    <?php 
} 
?> 

は以下productdetail.phpでコードです: if ($id != "")

<?php 
if ($id != "") 
{ 
    $link = mysql_connect("xxx", "xxx", "xxx"); 
    mysql_select_db("xxx"); 

    $sql = "SELECT * FROM products WHERE id = '$id'"; 
    $result = mysql_query($sql, $link); 
    $line = mysql_fetch_array($result, MYSQL_ASSOC); 
    $id = $line["id"]; 
    $name = $line["name"]; 
    $description = $line["description"]; 
    $image = $line["image"]; 
} 
?> 

<div class="product_name"><b><?=$name;?></b><br></div> 
<div><img class="product_image" src="<?=$image;?>"> 
    <div class="product_description"> 
     <?=str_replace("\n", "<BR>", $description);?> 
    </div> 
</div> 
<div class="backbutton"> 
    <a href="productlist.php"> 
     <img src="images/btn_back.gif" width="38" height="16" border="0"> 
    </a> 
</div> 
+0

ようこそ! PHPの 'mysql_ *'関数は廃止予定ですので、使用しないでください。なぜPHPのmysql_ *関数を使うべきではないのですか?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)を読んでください。それらを何に置き換えるか。 –

答えて

0

あなたのコードのこの部分に問題がある可能性ができます。 $id$_GET配列から取得する必要があります。次のようなものを試してみてください。

<?php 
if (!empty($_GET['id']) && $id = $_GET['id']) 
{ 
    $link = mysql_connect("xxx", "xxx", "xxx"); 
    mysql_select_db("xxx"); 

    $sql = "SELECT * FROM products WHERE id = '$id'"; 
    $result = mysql_query($sql, $link); 
    $line = mysql_fetch_array($result, MYSQL_ASSOC); 
    $id = $line["id"]; 
    $name = $line["name"]; 
    $description = $line["description"]; 
    $image = $line["image"]; 
} 
?> 

<div class="product_name"><b><?=$name;?></b><br></div> 
<div><img class="product_image" src="<?=$image;?>"> 
    <div class="product_description"> 
     <?=str_replace("\n", "<BR>", $description);?> 
    </div> 
</div> 
<div class="backbutton"> 
    <a href="productlist.php"> 
     <img src="images/btn_back.gif" width="38" height="16" border="0"> 
    </a> 
</div> 
+1

本当にありがとうございました! – Dora

関連する問題