2017-10-16 9 views
-1

イム指定されたオブジェクトは、MySQL助けてください:警告:mysqli_num_rows()私はすべてを試してみましたが、このコードで間違っているものをうまくできなかった

で、この動的テーブルでウェブサイトを作成しようと、パラメータ1がmysqli_resultされることを想定してい。

あなたはmysqli_num_rows()の引数ではなく、接続としてmysqli_query()の結果を使用する必要が

<?php 
// Script Error Reporting 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
?> 
<?php 
// Run a select query to get my letest 6 items 
// Connect to the MySQL database 
include "storescripts/connect_to_mysql.php"; 
$dynamicList = ""; 
mysqli_query($con,"SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); 
$productCount = mysqli_num_rows($con); // count the output amount 
if ($productCount > 0) { 
    while($row = mysqli_fetch_array($con)){ 
      $id = $row["id"]; 
      $product_name = $row["product_name"]; 
      $price = $row["price"]; 
      $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); 
      $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6"> 
     <tr> 
      <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td> 
      <td width="83%" valign="top">' . $product_name . '<br /> 
      $' . $price . '<br /> 
      <a href="product.php?id=' . $id . '">View Product Details</a></td> 
     </tr> 
     </table>'; 
    } 
} else { 
    $dynamicList = "We have no products listed in our store yet"; 
} 
mysqli_close($con); 
?> 

答えて

0

助けてください。同じことがmysqli_fetch_array()のために行く

$result = mysqli_query($con,"SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); 
$productCount = mysqli_num_rows($result); 

、それがあるべき

while($row = mysqli_fetch_array($result)){ 
関連する問題