数组到字符串转换错误的商店

时间:2016-05-31 10:23:55

标签: php mysql

我正在尝试使用PHP为我的网站创建“详细信息页面”。它正确连接,但是当我尝试插入图像和细节时,它会出现一个字符串错误

<div id="main">
  <section class="products">
  <?php
  if(isset($_GET["view_product"])) {

  ?>
<div class="product_ind">
<div class="image">

    </div>
<div class="image_details">

尝试将我的ProductName ProductPrice和Image放在这里^^                  

正如您所看到的,我已在此处进行了连接,但$row事情在上面无效。

$sql = "SELECT * from product";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
   // output data of each row
while($row = $result->fetch_assoc()) { ?>
<div class="product-card"> 
 <a href="./shop.php?view_product=<?php echo $row["ProductID"]?>"><img src="images/<?php echo $row["ProductImage"];?>"height="250" width="200"></img>
   <div class="product-info">
  <p><?php echo $row["ProductName"];?> $<?php echo $row["ProductPrice"];?>    </p>
    </div>
   </a>

   </div>

   <?php  
    }
    }
   }
  ?>
 </div>
 </section>
 </div>

1 个答案:

答案 0 :(得分:0)

print_r是一个函数,而不是一个数组,因此您有语法错误。删除调试p标签:

<div id="main">
  <section class="products">
  <?php
  if(isset($_GET["view_product"])) {

  ?>
<div class="product_ind">
<div class="image">

    </div>
<div class="image_details">
</div>
</div>
<?php
}
else {
$sql = "SELECT * from product";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
   // output data of each row
while($row = $result->fetch_assoc()) { ?>
<div class="product-card"> 
 <a href="./shop.php?view_product=<?php echo $row["ProductID"]?>"><img           src="images/<?php echo $row["ProductImage"];?>"height="250" width="200"></img>
   <div class="product-info">
  <p><?php echo $row["ProductName"];?> $<?php echo $row["ProductPrice"];?>    </p>
    </div>
   </a>

   </div>

   <?php  
    }
    }
   }
  ?>
 </div>
 </section>
 </div>
相关问题