Welcome Guest, Not a member yet? Register   Sign In
$this->table->set_heading() with row numbering?
#1

[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
#2

[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
#3

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

Did you find answer your thread yet? Thread
#4

[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:
#5

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

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

[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.
#8

[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++;
    }
}
#9

[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.




Theme © iAndrew 2016 - Forum software by © MyBB