Welcome Guest, Not a member yet? Register   Sign In
Noob question.
#1

[eluser]jav99[/eluser]
hi, am pretty new to code igniter, but am pretty excited bcz it's potential, am trying to make a simple and i would like to see if someone could give me pointers,

i want the CI to take the query, and print for each 4 of the results

example

query result, let's say this is the ID row, the results would go from 1 to 0L 1,2,3,4,5,6,7,8,9,0

then am wondering how could i print the results in a group containing results from 1 - 4, then start the loop again but containing the results from 5 - 0 and so on.

Sorry for the nub questions, but any help will be much appreciated...
#2

[eluser]stuffradio[/eluser]
Something like this

Code:
//yourcontroller.php

class Yourcontroller extends Controller
{

    function Yourcontroller()
    {
      parent::Controller();
    }

    function index()
    {
      $this->load->model('yourmodel');
      $data['results'] = $this->yourmodel->listAll();
      $this->load->view('myview', $data);
    }

}

Code:
//yourmodel

class Yourmodel extends Model
{

    function Yourmodel()
    {
      parent::Model();
    }

    function getAll()
    {
     $query = $this->db->get("table_name");
     return $query->result();
    }

}

Code:
//myview.php

<?php
$i = 0; //tell us what row number we're on
foreach ($results as $row):
    if ($i == 3):
      echo $row->id . "<br />";
    $i=0;
   endif;

$i++;
endforeach;
?&gt;

Your question isn't 100% clear on how you want the results to be displayed, but pretty much this gets every row in the table from the model, and every 4 rows it will enter a line break. This is just an example and I hope I did wrote something that will help you Smile
#3

[eluser]jav99[/eluser]
OMG THAT WAS FAST!! HAHA, and a slap to the face of pure goodness! thanks man,

well the way i was trying to get it to show was in groups, bcz am using a sort of glider to partially show the results, using as an example the days of the week contained in a table.

say it prints groups of 3 days like:

--- css div-----
monday (id = 1)
tuesday (id = 2)
wednesday (id = 3)
----- then the loop breaks, and closes the divs and ask if there are more days (this one is easy) if there are open another div and print--
Thursday (id = 4)
friday (id = 5)
saturday (id = 6)
----- then the loop breaks, and closes the divs again

Man , thanks for your help, u have been very helpful so far, am just skimming the surface of code igniter, but am getting very excited!!!
#4

[eluser]stuffradio[/eluser]
Glad to help and glad you're excited Smile
#5

[eluser]huzzi[/eluser]
Next time try to put a relevant thread title and you'd get even faster response Smile




Theme © iAndrew 2016 - Forum software by © MyBB