Unexpected results with a nested recordset
Hi Ray, I have a page which lists all tests that are available to the logged in user, and which displays a badge next to each test showing if it has already been completed and on which date. This is done using a nested recordset and a Show If Recordset Not Empty command as follows:
<?php
$rsTests = new WA_MySQLi_RS("rsTests",$Composite,0);
$rsTests->setQuery("SELECT * FROM CPD_test WHERE CPD_test.Secondary = 0 AND FCANo IS NULL AND Live = 1 ORDER BY CPD_test.Title");
$rsTests->execute();
?>
<?php
$wa_startindex = 0;
while(!$rsTests->atEnd()) {
$wa_startindex = $rsTests->Index;
?>
<?php
$WADACPD = new WA_MySQLi_RS("WADACPD",$Composite,0);
$WADACPD->setQuery("SELECT CPD.CPD_ID, CPD.User_ID, CPD.Course_name, CPD.`Date` FROM CPD WHERE Score > 0 AND CPD.User_ID = ? AND CPD.Course_name REGEXP ? ORDER BY CPD.`Date` DESC");
$WADACPD->bindParam("i", "".$_SESSION['CPD_ID'] ."", "-1"); //colname
$WADACPD->bindParam("s", "".(preg_quote($rsTests->getColumnVal("Title",false))) ."", "-1"); //paramTest
$WADACPD->execute();?>
<?php if ($WADACPD->TotalRows > 0) { // Show if mysqli recordset not empty ?>
Completed <?php echo date("d.n.y",strtotime($WADACPD->getColumnVal('Date')));?>
<?php } // Show if mysqli recordset not empty ?>
<?php
$rsTests->moveNext();
}
$rsTests->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
I've discovered an anomaly though - there are two tests, one called "Certification" and the other "Senior Manager & Certification Regime (SM&CR)" and the above code is showing both of these as having been completed, even though the one called "Certification" hasn't been completed. I've tried various alterations to the above query but can't get it to work as it should. Can you help?