I\'m trying to fetch all records from my table on my site, I have the following
$sth = $conn->prepare(\"SELECT * FROM directory WHERE user_active != \'\'
You need to use a loop:
while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
echo $result[First_Name];
echo ' ' . $result[Surname];
}
Or you could use fetchAll method:
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $result) {
echo $result[First_Name];
echo ' ' . $result[Surname];
}
And Note: If First_Name
and Surname
are not constants, then you should use the string as the key name.
$result['First_Name']
and $result['Surname']