没有Erros,但没有数据出现

时间:2015-09-01 21:04:00

标签: php

这是我在此页面上唯一的PHP,我正在尝试获取产品的详细信息,以显示更大的图像和有关该产品的其他详细信息。我没有得到任何PHP页面的错误,但没有显示该产品的内容。     

    $database = new Database();
    $conn=$database->getConnection();
    $tree_product = new tree_product($conn);
    $tree_product->id=$_GET['detailsid'];
    $stmt=$tree_product->readDetails();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){

?>

<div id="main_tree">
 <img src="img/lg_tree/<?php echo $row['lgpic']; ?>" alt="" />
</div>

<div id="tree_detail">
 <span class="cat_name">Name: </span><span class="name"><?php echo $row['name']; ?></span><br>
 <span class="cat_name">Latin Name: </span><span class="latin"><?php echo $row['name']; ?></span><br>
 <span class="cat_name">Price: </span><span class="price">$<?php echo $row['name']; ?></span><br>
 <span class="cat_name">Description: </span><span class="description><?php echo $row['name']; ?></span><br>
</div>

</main>

<?php
   }
?>

2 个答案:

答案 0 :(得分:0)

try

use try catch

and change your code to

 $rows=$stmt->fetchAll(PDO::FETCH_ASSOC);
 foreach($rows as $row)
 {
   // html
 }

答案 1 :(得分:0)

 // connection
   try {
    $stmt=$tree_product->readDetails();
    $rows=$stmt->fetchAll(PDO::FETCH_ASSOC);
   } catch (Exception $e) {
     die("Oh noes! There's an error in the query!");
   }

   // for loop
相关问题