How can you use the following sample data either with a foreach
or while
-loop?
I get the following sample data by running
$answers = pg_fetch_all ( $result );.
Sample data
[0]=>
array(3) {
["answer"]=>
string(7) "This is the answer"
["username"]=>
string(5) "roope"
["was_sent_at_time"]=>
string(26) "2009-08-20 23:30:46.200017"
}
--- cut ---
[3]=>
array(3) {
["answer"]=>
--- cut ----
However, I am not sure whether it is the best way to extract the data, since I am not sure how you can extract the data from the above format. I unsuccessfully ran
1
foreach ( $answers as $answers[] => $answers['answer'] ){
echo $answers['answer']
echo $answers['username'];
echo $answers['was_sent_at_time'];
}
#1 is the only way by which I have got data out of the resource. I have tried the #2 way unsuccessfully.
2
while ( $answer_row = pg_fetch_array( $result ) ) {
echo $answer_row['username'];
echo $answer_row['was_sent_at_time'];
echo $answer_real['answer'];
}
This way gives nothing as an output which is surprising, since the sample data shows me that each answer has the corresponding fields.