Yes you are right. I have changed this to,
<form action="?searchview" method="post">
<div>
<label for="student">By student:</label>
<select name="id" id="id">
<?php foreach ($learners as $learner): ?>
<option value="<?php htmlout($learner['id']); ?>"><?php
htmlout($learner['learner']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<input type="hidden" name="action" value="searchview">
<input type="submit" value="Search">
</div>
</form>
I also had the wrong name for the column in the database. It is not called ‘id’ but ‘userid’.
So the pdo statement now reads,
if (isset($_POST['action']) and $_POST['action'] == 'searchview')
{
include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
// Build the new list of notes rows where id's matches
try
{
//$result = $pdo->query('SELECT id, absence, late, equip, effort, comment, date, time FROM notes);
$sql = 'SELECT userid, effort FROM notes WHERE
userid = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_POST['id']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error fetching list of notes.';
include 'error.html.php';
exit();
}
$result = $s->fetchAll();// see p.196
foreach ($result as $row)// see p.196
{
$newNotes[] = array('userid' => $row['userid'], 'effort' => $row['effort']);
}
include 'searchview.html.php';
exit();
}
And it is working,
Thanks,
Shane