Welcome Guest, Not a member yet? Register   Sign In
How to output database to table formated into rows and columns
#1

[eluser]brandontran[/eluser]
I have a database with 8 entries. How can I get the following database output to show a table with 2 rows?

I am trying to display those entries like:
Code:
<table><tr>
<td>title 1</td>
<td>title 2</td>
<td>title 3</td>
<td>title 4</td>
</tr><tr>
<td>title 5</td>
<td>title 6</td>
<td>title 7</td>
<td>title 8</td>
</tr></table>

My controller looks like this:
Code:
&lt;?
class Main extends Controller {
    function Main()
    {
        parent::Controller();    
        $this->load->helper("url");
    }
    
    function index()
    {
        $this->load->database();
        $data['query'] = $this->db->get('photo', 8,0);        
        $this->load->view('main/home' );
    }
}

My view looks like this:
Code:
&lt;? foreach ($query->result() as $row): ?&gt;
<td>&lt;?=$row->photo?&gt;</td>
&lt;? endforeach; ?&gt;

My second question is, I feel that maybe the database call needs to go into a model. While the current setup works, is it correctly setup with the codeigniter concept?

Thanks for the help guys!


Messages In This Thread
How to output database to table formated into rows and columns - by El Forum - 08-29-2009, 04:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB