![]() |
Help getting info from database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Help getting info from database (/showthread.php?tid=20483) |
Help getting info from database - El Forum - 07-11-2009 [eluser]Unknown[/eluser] Hello, I've been having trouble getting information to the view from a database. This is the situation: There are a total of three databases. The first is a database for a student that records all their personal information. The second is a database for classes the student can register for. This database contains all the information on that particular class. The third database is used to associate a student with a particular class. It takes the student id and the class id and puts it into a 'studentid' and 'classid' field. I can fetch the studentid without a problem, I can then use that to find which classes in the associated database are registered to that student. The problem occurs when I try to get each classid pass it to a query that finds the id in the class database and then passes that information to the view. Typically I can only get one result to show up. Do I have to add each to an array? I'm not sure how to get it to work. I'm new to php and especially the MVC model, so please, any help would be appreciated. Thank you. Controller Code: function reviewclasses() View Code: <html> Help getting info from database - El Forum - 07-11-2009 [eluser]Herb[/eluser] Let me see if this is right? You want to get a list of classes enrolled in then list the data on the class. In your controller you are looping over a query that extracts one class at a time and overwrites $data['query'] on each iteration. Therefore, you only pass the result of the last query. Try building a multi-dimentional array: $data[$classid]['query_result_field']. Then do nested foreach in the view to extract the data. |