This is a weird problem. I have a field called status in a database table called Parents. Via a php script, I entered a bunch of parents with status of 'active'. Later, I used phpmyadmin to change two of them to a status of 'dormant'. When I run a query asking for rows with status of active, all is well in both phpmyadmin and in my php script. When I run a query asking for rows with status of dormant, phpmyadmin returns the two rows whose status is dormant, but my php script does not return any rows. Here are the relevant pieces of the code:
// get value of radio button for $active
$active = stripslashes(strip_tags($_POST['active']));
if (!$active) {
$active = 'active';
}
// Similar process for value of $myOrderby,
// which can have value of 'name' or 'email' and works fine
$query = "SELECT
Parents.parentID,
Parents.parentName,
Parents.parentEmail,
Students.nickName,
Students.Lname
FROM Parents, Students
WHERE Parents.parentID=Students.parentID
AND Parents.status=:active
ORDER BY $myOrderby ASC" ;
$stmt = $db->prepare($query);
$stmt->bindValue(':active', $active, PDO::PARAM_STR);
try {
$stmt->execute();
$affected_rows = $stmt->rowCount();
if ($affected_rows > 0) {
// various actions...
}
} catch (PDOException $ex) {
$message = $ex->getMessage() ;
$filename = 'admin-parents' ;
notifyMe($message, $filename) ;
}
Curiously, however, if I again use phpmyadmin to change the two rows whose status is 'dormant' back to a status of 'active' (not using any punctuation in the input box) those two rows do NOT show up in the php results for all active parents. That is the problem that started me on this entire quest.
CLARIFICATION: myphpadmin query ALWAYS returns correct result for these two rows, both when status is 'active' and when status is 'dormant'. (I change them via myphpadmin.) However, php script NEVER returns these two rows, regardless of their status.