doubledee
06-18-2012, 09:48 AM
I have the following code that is not throwing an error like I am used to...
// Build query.
$q2 = "SELECT MAX(comment_no) AS lastCommentNo
FROM comment
WHERE article_id=?";
// Prepare statement.
$stmt2 = mysqli_prepare($dbc, $q2);
// Bind variable to query.
mysqli_stmt_bind_param($stmt2, 'i', $articleID);
// Execute query.
mysqli_stmt_execute($stmt2);
// Store results.
mysqli_stmt_store_result($stmt2);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt2)==1){
// Maximum Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt2, $lastCommentNo);
// Fetch record.
mysqli_stmt_fetch($stmt2);
// Increment CommentNo.
$commentNo = $lastCommentNo + 1;
}else{
// Maximum Not Found.
$_SESSION['resultsCode'] = 'COMMENT_MAXIMUM_NOT_FOUND_2049';
Normally to test the "Error Branch" of my code above, I would change $articleID to $articleID2, thus breaking my query and launching the ELSE branch of my code with the Error-Message.
The problem seems to be that $articleID2=0 and so my query returns a NULL for the MAX() which technically counts as a row being returned?!
Follow me?!
That isn't the behavior I am looking for.
Debbie
// Build query.
$q2 = "SELECT MAX(comment_no) AS lastCommentNo
FROM comment
WHERE article_id=?";
// Prepare statement.
$stmt2 = mysqli_prepare($dbc, $q2);
// Bind variable to query.
mysqli_stmt_bind_param($stmt2, 'i', $articleID);
// Execute query.
mysqli_stmt_execute($stmt2);
// Store results.
mysqli_stmt_store_result($stmt2);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt2)==1){
// Maximum Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt2, $lastCommentNo);
// Fetch record.
mysqli_stmt_fetch($stmt2);
// Increment CommentNo.
$commentNo = $lastCommentNo + 1;
}else{
// Maximum Not Found.
$_SESSION['resultsCode'] = 'COMMENT_MAXIMUM_NOT_FOUND_2049';
Normally to test the "Error Branch" of my code above, I would change $articleID to $articleID2, thus breaking my query and launching the ELSE branch of my code with the Error-Message.
The problem seems to be that $articleID2=0 and so my query returns a NULL for the MAX() which technically counts as a row being returned?!
Follow me?!
That isn't the behavior I am looking for.
Debbie