Frage

I'm trying to simply echo results out on the screen from my database. I'm quite new with PDO, and I've been searching on this site for an answer that works, but have found none so far.

$results = $MyConnection->prepare("SELECT Antwoord1, Antwoord2, Antwoord3 FROM CCOpendag ");
$results->execute();
$foundResults = $results->fetchAll(PDO::FETCH_ASSOC);

echo $foundResults;

This piece of code simply echoes out 'Array'. What I want to achieve is that I get the results from these 3 columns and display them on the screen. If somebody could help me out, that would be amazing.

War es hilfreich?

Lösung

print_r($foundResults) or var_dump($foundResults)

Andere Tipps

It shows "Array" because you need to iterate over the results, and not simply just echo it out. Use var_dump or print_r and you should see the array; you can then loop out the results as you wish - var_dump will just show you the whole array.

$foundResults is an array with all the records . You can view the array by using print_r($foundResults).

Or it will be better if you use a loop to read each rows while($foundResults=$results>fetch(PDO::FETCH_ASSOC)) {

echo $foundResults['Antwoord1'].$foundResults['Antwoord2'];

}

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top