Welcome Guest, Not a member yet? Register   Sign In
help with table + pagination
#1

[eluser]e.abubakr89[/eluser]
Hello

can anybody help me in my project ?
i am new to codeigniter, but I learn quickly

my problem is that I created already a pagination table for my database with (pagination) and (table) libraries

I have 3 columns (id,message,sender)

firstly I need to display just first 30 words of the message in the table

secondly, I need to link the (message) column (link every message td in each row) to enable user to click on it and go to the full message page

how can I make it. please ?
#2

[eluser]Naveen Reddy[/eluser]
Hey,

1. If you want to display 30 words of message in the table, then use substr() of php. Its quite easy.

2. Your id is primary key so, you have to make another controller to show the full message. Lets say, you have one controller called fullmsg.php,and it has an action method called show($id) then the logic is like this...

Code:
<a href='&lt;?php print base_url(); ?&gt;fullmsg/show/id'>your 30 words </a> . Thats it...

Note: that id in href is a numeric id.
#3

[eluser]e.abubakr89[/eluser]
===============
Hi Naveen Reddy
:-)

Thanks, But I Have created my pagination with traditional way by setting config variables of pagination in a controller as:

Code:
function outbox()
    {
          $this->load->library('table');
        $this->load->library('pagination');

        $config['base_url'] = 'http://localhost/we_hona/index.php/private_messages/outbox';

         $this->db->where('from',$this->input->post('session_username'));
        $config['total_rows'] = $this->db->get('pm')->num_rows();
        $config['per_page'] = 3;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<div id="outbox_pages">';
        $config['full_tag_close'] = '</div>';
        
        $this->pagination->initialize($config);

        $this->db->where('from',$this->input->post('session_username'));
        $data['records'] = $this->db->get('pm', $config['per_page'],               $this->uri->segment(3));
      
        $this->load->view('outbox_messages',$data);

then go to my view and use the table.generate($records) to generate the pagination table

Code:
&lt;?php
                echo $this->table->generate($records); ?&gt;
        &lt;?php echo $this->pagination->create_links(); ?&gt;

The problem here that I can not find the tools that help me in :

1 - control the records output ( as using substr() with message records )
as I can just set config and get the pagination and it return the full data of DB with no options for more controller

2 - also I can not reformatting the output records in the table (as link the record I need)

I hope that the message received

thanks
#4

[eluser]e.abubakr89[/eluser]
Hello all

I have found my solution
:lol: :lol: :lol:

by do not passing the $records directly to table.generate() function

but firstly I have to use table.add_row() function and set what I need
for example
I set my controller as

Code:
function outbox()
    {

          $this->load->library('table');
        $this->load->library('pagination');

        $config['base_url'] = 'http://localhost/we_hona/index.php/private_messages/outbox';

         $this->db->where('from',$this->input->post('session_username'));
        $config['total_rows'] = $this->db->get('pm')->num_rows();
        $config['per_page'] = 3;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<div id="outbox_pages">';
        $config['full_tag_close'] = '</div>';

        
        $this->pagination->initialize($config);

        $this->db->where('from',$this->input->post('session_username'));
        $records = $this->db->get('pm', $config['per_page'], $this->uri->segment(3));
        foreach ($records->result() as $item)
        {
            $q[] = $item;
        }
        $data['records'] = $q;
        
        $this->load->view('outbox_2',$data);

    }

then go to outbox_2 view and using foreach to execute $records record by record to pass it to table by table.add_row , and I can specify how message td will display
Code:
&lt;?php
foreach ($records as $item)
{
   $this->table->add_row(array($item->from,$item->to,$item->title,"<a >id."' >".substr($item->message,0,8)." </a>"));
}

echo $this->table->generate();
?&gt;

I dont know why code editor remove the href of my code

===========================

thanks for all who helped me

goodbye
#5

[eluser]Dinni Hayyati[/eluser]
Hi there..

I need to create pagination too.
I have used those scripts and
PHP error was encountered
Message: Undefined property: CI_Loader::$table

do you have any idea why is that or why don't those scripts work at my project?
thank you
#6

[eluser]e.abubakr89[/eluser]
Hi Dinni
This post is written a year ago, when the used codeigniter was 1.7. so
1- use codeogniter 2.0.X
2- type the command
Code:
$this->load->library('table');
before using add_row function, like:
Code:
&lt;?php
$this->load->library('table');
foreach ($records as $item)
{
   $this->table->add_row(array($item->from,$item->to,$item->title,"<a >id."' >".substr($item->message,0,8)." </a>"));
}

echo $this->table->generate();
?&gt;

any time.

Hey Dinni, where are you from? (nationality !)
#7

[eluser]Dinni Hayyati[/eluser]
mm i see..

i'm an indonesian
thanks but i'll be back if it doesn't work Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB