我一直在使用这段代码,它运行良好,但现在我输入了一个只返回一个结果的查询,突然$findproductsrow
就变成了NULL
. 我该如何解决这个问题?(第一个 $findproductsresult 不为空,第二个为空。)如果只返回一行,我是否需要添加一个子句?
$UserID = $_SESSION['userID'];
$findproductsstmt = mysqli_prepare($connection, "SELECT DISTINCT PID FROM prices WHERE UserID = ? and Manu = 0");
mysqli_stmt_bind_param($findproductsstmt, 'i', $UserID);
mysqli_stmt_execute($findproductsstmt);
$findproductsresult = mysqli_stmt_get_result($findproductsstmt);
if(mysqli_num_rows($findproductsresult) == 0) {
echo('This user is not retailing any products.');
}
else{
$findproductsrow = mysqli_fetch_array($findproductsresult, MYSQLI_ASSOC);
var_dump($findproductsresult);
while($findproductsrow = mysqli_fetch_array($findproductsresult, MYSQLI_ASSOC)){
$_SESSION['PID'] = $findproductsrow['PID'];
include '../includes/baseproductlist.php';
}
}