0

Here is my code:

http://pastebin.com/husbQ7hc

On line 33 it has:

echo $value;

How can I have it that I can use it like below:

echo $value['module_name'];
echo $value['module_name_id'];
echo $value['module_image'];

Hope someone can help.

Thanks

3
  • Place your pertinent code in your question as well. Commented Apr 29, 2013 at 23:24
  • Do a var_dump of $final Commented Apr 29, 2013 at 23:24
  • I placed the var_dump($final); on line 20. This is the output pastebin.com/Mw9vtRTP Commented Apr 29, 2013 at 23:33

1 Answer 1

2

During your final result fetch on line 13:

// Retrieve results
while ($row = $result->fetch_assoc()) {
    // Add to final array via counter if valid course is found
    if (in_array($row['course_name'], $courses)) {
            $final[$row['course_name']][] = $row['module_name'];
    }
}

Rather than storing just the column value of $row['module_name'], store the entire row to access it later:

$final[$row['course_name']][] = $row;

Then when you "loop through the internal values" on line 32 you can access any column you want using:

echo $value['module_name'];
echo $value['module_name_id'];
echo $value['module_image'];
Sign up to request clarification or add additional context in comments.

2 Comments

How can I get it to display the course description after the course name on line 29. course_desc is in the Table courses.
sorry your link is no longer valid so i can't see your code. However, if it is a value from another table that you are after then I would suggest you do a SQL JOIN in you main query so you can access those values later in your $final array. If this isn't correct then paste your code in your question and I'll look at it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.