2014-11-20 9 views
0

我试图从订单表中打印出Product_Name和Order_Date,但不断收到第35行的错误“num_rows线”。尝试在内部连接语句上尝试获取非对象属性的错误

<?php 
$servername = "localhost"; 
$username='root'; 
$password = ""; 
$dbname = "login"; 
?> 
<html><<html> 
    <head> 
     <title>Cart</title> 
     <link rel="stylesheet" href="tabMenu.css" type="text/css"> 
    </head> 
    <body> 

    </body> 
</html> 

<?php 
$mysqli = new mysqli($servername,$username, Null, $dbname); 
// Check connection 
if ($mysqli->connect_error) { 
die("Connection failed: " . $mysqli->connect_error); 
} 

session_start(); 

$results="Select orderline.Order_Date,p.Product_Name" 
     . "from orderline" 
     . "inner join product p" 
     . "on orderline.Product_ID=p.Product_ID"; 

$num=$mysqli->query($results); 



if ($results->num_rows) 
    { 
    while ($row=$results->fetch_object()) 
      { 
     echo "{$row->Order_Date} {$row->Product_ID} <br>"; 
      } 
    } 
    else 
    { 
    echo "No Results";} 

在此先感谢任何帮助将是伟大的。

回答

3

$resultsstring,字符串不是PHP中的对象(至少不是正常情况)。

你需要看看results objectnum_rows属性:

$resultSet = $mysqli->query($results); 
$numRows = $resultSet->num_rows; 

if ($numRows > 0) { 
    while ($row = $resultSet->fetch_object()) { 
     echo "{$row->Order_Date} {$row->Product_ID} <br>"; 
    } 
} 

Here is some documentation

相关问题