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

#1
[eluser]timboland[/eluser]
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?


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

//view
<?php
foreach($query->result() as $row)
{

    print "<tr class='rowstyle'>
        <td>$row->heading</td>
        <td>$row->description</td>
        <td>$row->isactive</td>
        <td>$row->sortnumber</td>";
    
    // 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>";
?&gt;

#2
[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:
Code:
if ($query->num_rows() > 0) {
    foreach ($query->result() as $row) {
        //statements here...
    }
}

else {
    //statements here...
}

#3
[eluser]TheFuzzy0ne[/eluser]
I second that.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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