获取行数时出错

时间:2016-05-07 21:52:52

标签: php mysqli

我在执行以下操作时遇到错误“试图在第76行获取非对象的属性”:

 require_once 'DBConnection.php' ;
$connection = new mysqli($hostname, $username, $password, $database);

if ($connection->connect_error) die ($connection->connect_error);
$query = "Select * From product where productCategory = $productCategory";
$result = $connection->query($query);

$rows = $result->num_rows;   //line 76

for ($j = 0 ; $j < $rows ; ++$j)
{
    $result->data_seek($j);

    $row = $result->fetch_array(MYSQLI_NUM);

1 个答案:

答案 0 :(得分:1)

您应该使用 mysql_num_rows()功能。对于您的给定代码,它必须类似于mysql_num_rows($result)

您可以参考mysql_num_rows()的PHP文档以获取更多详细信息。