Welcome Guest, Not a member yet? Register   Sign In
Display pagination results within html

I followed the codeigniter from scratch day 7 tutorial[/url]: And I have pagination working and displaying results properly in a table. What i want to be able to do, is output each result inside some html in my view. I have figured out two ways to do it, but I don't think either one is the right way to do things.

1st way: use foreach loop to loop through results, and echo both html and pagination result data. Something like this:

foreach ($records as $r)
       $subFirst = $r['subFirstName'];
        $subLast = $r['subLastName'];
        echo('<div class="row">');
        echo(' <h5> Subject Name</h5> ');
        echo('<div class="8 columns"');

That looks absolutely terrible, makes styling difficult, and I'm pretty sure terrible practice.

The second way is to use the index of the pagination results along with the uri segment containg the page number to display results like so:

<div class=somestlye>
     &lt;?php echo($records[0 * $this->uri->segment(3) ] ['subFirstName']); ?&gt;
<div class=somestlye>
     &lt;?php echo($records[1 * $this->uri->segment(3) ] ['subFirstName']); ?&gt;

This is somewhat better, but the math might make some things unclear, and if I decide to change the number of results on the page, this might be hard to update. Also I'd need to code for a special case for the first page of the list where the uri segment doesnt exist and is therefore 0.

I'd link to an example, but it wont let me because I'm new.

Even if i use a table, I would need to put html in the table to display the results correctly.

Any suggestions of how to accomplish this are appreciated.

Welcome to the CodeIgniter forums!

I don't understand the math involved in your view, but if I understand you correctly. I'd put this into my view:
&lt;?php foreach ($records as $r): ?&gt;

    <div class="row">
        <h5>Subject Name</h5>
        <div class="8 columns">
            &lt;?php echo $r['subFirstName'].' '.$r['subLastName']; ?&gt;

    </div>&lt;?php endforeach; ?&gt;

I have put two blank lines in intentionally. Due to how PHP short tags work, this should ensure that your output source code is nice and neat, but it's not essential.

Hope this helps (or did I completely miss the point?)

That's perfect thank you. Kind of new to PHP, didn't know you could do that. You've saved me a lot of time.

Theme © iAndrew 2016 - Forum software by © MyBB