I have a question about error-handling and my WHILE loop.
First, here is the code for my query…
$q8 = "SELECT COALESCE(m.username,'Non-Member') AS username
FROM visitor_log AS v
LEFT OUTER JOIN member AS m
ON m.id = v.visitor_id
WHERE v.member_viewed_id=?
ORDER BY v.created_on DESC
LIMIT 10";
// Prepare statement.
$stmt8 = mysqli_prepare($dbc, $q8);
// Bind variable to query.
mysqli_stmt_bind_param($stmt8, 'i', $memberID);
// Execute query.
mysqli_stmt_execute($stmt8);
// Store results.
mysqli_stmt_store_result($stmt8);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt8)>0){
// Visitors Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt8, $visitorUsername);
// Fetch below in loop...
}else{
// Visitors Not Found.
// Do Nothing...
}
And then here is the loop I am concerned about…
// Loop through Friends.
while (mysqli_stmt_fetch($stmt8)){
//Some code here...
}
I am worried that if my query (i.e. mysqli_stmt_fetch($stmt8))) returns “0” or “NULL” that my loop could go crazy?!
For a preliminary test, I changed my query to LIMIT 0, and my loop seemed to be okay, but I still feel like something is missing… :-/
Suggestions?
Thanks,
Debbie