Printing an [] from a mysql table

I have a mysql table I run a select on

$sql = 'SELECT optionName FROM providers_options WHERE providerID = :id';
$prepare = $conn->prepare($sql);

$parameters = array(
':id' => $id

$provider_options = $prepare->fetch(); 

W"hen I print_r($provider_options) to see the resulting array, I only get 1 result, but when I run t he query, I get 4.
Is $provider_options not the resulting array?
what is?

No, it isn’t the array. You just got the first row. You need to iterate through all rows. Something like this…

while($provider_options = $prepare->fetch()){

1 Like

Or, as it’s PDO, you could use fetchAll() to get the entire result set into an array.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.