Here I am writing the code fully to explain my problem. the links are generated but the list is not. what could be the problem? thanks..
require 'database.php'; $query="SELECT subject.subjectName, subject.subjectId FROM course,subject where subject.subjectId=course.subjectId and course.memberId=1"; $courses=$db->query($query); ?> <!doctype html> <html> <head> <title>foreach</title> </head> <body> <?php foreach ($courses as $course):?> <a href="#"> <?php echo $course['subjectName'];?> </a> <br> <?php endforeach; ?> <ul> <?php foreach ($courses as $course):?> <li> <?php echo $course['subjectName'];?> </li> <?php endforeach; ?> </ul> </body> </html>
foreachtwice would not cause an issue unless$coursesis no longer in the scope on second iteration. I suspect he's either out of scope, or$coursesactually implementsArrayAccessandIteratorand makes a mess of it. Need more info.