Multi-Dimensional Array Get Column

At the moment the query below does what it should, queries a questions table for a series of questions and the looks for the corresponding answers from another table depending on a submissions id. It then passes a multi dimensional array to a CSV export file.

I made a couple of mistakes when filling in the questions from the admin panel in WordPress and had to delete them and add the question again. Because of that the question id has a couple of values, though the CSV contains all the right data because of the submissions id. The CSV output looks something like –

Q1, Q2, Q3, Q4

12 04 75 22

33 43 54 88

or at least I think it does. I need to be able to print out individual columns, so for Q3 $answers[2] and so on, however, I am not able to manage it. I have tried everything I can think of to get it to print columns but with no luck.

Can anyone see an obvious mistake?

$qry = “SELECT ” . $this->tables[‘db_question’] . “.id, ” .
$this->tables[‘db_question’] . “.sequence, ” .
$this->tables[‘db_question’] . “.question, ” .
$this->tables[‘db_answer’] . “.answer ” . ” FROM ” . $this->tables[‘db_question’] . “, ” . $this->tables[‘db_answer’] . ” WHERE ” . $this->tables[‘db_question’] . “.id = ” . $this->tables[‘db_answer’] . “.question_id ” . ” AND ” . $this->tables[‘db_answer’] . “.registration_id = ” . $participant[“id”] . ” ORDER by sequence”;
$answers = $this->oModelAttendees->getWpDb()->get_results($qry, ARRAY_A);
foreach ($answers as $answer) {
$csv_output .= $s . $answer[“answer”];
}
$csv_output .= $et . “rn”

Thanks in advance

Read more here:: Multi-Dimensional Array Get Column

Leave a Reply

Your email address will not be published. Required fields are marked *