CodeIgniter Forums

Full Version: $this->table->set_heading() with row numbering?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]veledrom[/eluser]
Hi,

I'm using $this->table->set_heading('NAME', 'SURNAME'); How can I add numbering to rows?

Thanks

# NAME SURNAME
1
2
3
4

El Forum

[eluser]Otemu[/eluser]
Hi,

You could use the technique listed here

Example of the technique:
Code:
SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id AND e2.job_id = 10) AS rownumber
FROM employee e
WHERE job_id = 10
ORDER BY emp_id

In your model you could add count and then just return the rownumber column in your view

El Forum

[eluser]veledrom[/eluser]
I used this example.

Did you find answer your thread yet? Thread

El Forum

[eluser]Otemu[/eluser]
[quote author="veledrom" date="1339071327"]I used this example.

Did you find answer your thread yet? Thread[/quote]

Am glad you asked this question as I was using a completely different technique which I knew was inadequate basically I was incrementing a number within my for loop and just outputting the number as a column, I was eventually going to look for a much more efficient way to do this, the methods above seem much better.

No I haven't got a full answer to mu question yet, this is when your going to tell me you have the solution right :lol:

El Forum

[eluser]CI_expert_indian[/eluser]
Smile I am also using for loops for these type of task ...

El Forum

[eluser]veledrom[/eluser]
I'll just put variable in query, of course with some security validations.

El Forum

[eluser]veledrom[/eluser]
[quote author="deep_sheera" date="1339074475"]Smile I am also using for loops for these type of task ...[/quote]

So do I but can you add numbering to rows when using pagination and table library? If you can, show me what you've got.

El Forum

[eluser]Learn CodeIgniter[/eluser]
Code:
public function add_table_id()
{
    // Grab an array of users from the database
    $data = $this->your_model->your_function();

    // Setting headings for the table
    $this->table->set_heading('Row id', 'heading 2', 'heading 3', 'keep adding');

    $row_id = 1;

    foreach ($data as $value => $key)
    {
        // Adding row to table
        $this->table->add_row($row_id, $key['field1'], $key['field2'], $key['keep adding what you need']);
        $row_id++;
    }
}

El Forum

[eluser]veledrom[/eluser]
Thanks. I'll keep this in mind if I need it in future because I decided write my own pagination library instead of using CIs.