• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Queries

I have a grid of info that I need to display, most of these values are stored in 1 table but there is 1 column that has many values and stored in a child table. What is the best way to handle this in a MVC system?

//easy to get from one table
function list_topics()
$data['query'] = $this->Topic_model->ReadAllTopics();
$this->load->view('manage/list_topic_view.php', $data);

foreach($query->result() as $row)

    print "<tr class='rowstyle'>
    // HERE is where I need to print out the details child table
    // every row has different child records
    // What is the best way to dip into the database & pull these records?
    // Do I do it in the view?    

    print"<td><a >Manage Image</a></td></tr>";
print "</table>";

[eluser]Charles Garrison[/eluser]
My understanding of the MVC design would indicate that you do not want to do the processing in the view. I would probably build the html table in the controller and pass the it to the view as a string.

A couple of other suggestions:
- The "print" keyword is a bit slower than "echo" because it returns a value, FYI.
- It's a good idea to test your query results like this:
if ($query->num_rows() > 0) {
    foreach ($query->result() as $row) {
        //statements here...

else {
    //statements here...

I second that.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.