• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination and table error.

#1
[eluser]ede196620[/eluser]
So i have functions view update and delete. Update and delete works as it suppose to but the view function dose not perform as it suppose to fore some reason it keeps trowing me these 2 errors

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: table

Filename: views/display_view.php

Line Number: 15


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: pagination

Filename: views/display_view.php

Line Number: 16

i cant figure out i looked at all of my code 100 times and cant find where i went wrong maybe some one can spot the mistake i am posting my view and the controller.

CONTROLLER

Code:
class Display extends CI_Controller {

private $limit = 5;

function __construct()
{
  parent::__construct();

  $this->load->library(array('table','form_validation'));
  
  $this->load->model('display_model','',TRUE);
}

function index($offset = 0, $order_column = 'QID', $order_type = 'asc')
{

  if (empty($offset)) $offset = 0;
  if (empty($order_column)) $order_column = 'QID';
  if (empty($order_type)) $order_type = 'asc';
  //TODO: check for valid column
  
  // load data
  $querys = $this->display_model->get_paged_list($this->limit, $offset, $order_column, $order_type)->result();
  
  // generate pagination
  $this->load->library('pagination');
  $config['base_url'] = site_url('display/index/');
  $config['total_rows'] = $this->display_model->count_all();
  $config['per_page'] = $this->limit;
  $config['uri_segment'] = 3;
  $this->pagination->initialize($config);
  $data['pagination'] = $this->pagination->create_links();
  
  // generate table data
  $this->load->library('table');
  $this->table->set_empty(" ");
  $new_order = ($order_type == 'asc' ? 'desc' : 'asc');
  $this->table->set_heading(
   'No',
   anchor('display/index/'.$offset.'/Question/'.$new_order, 'Question'),
   anchor('display/index/'.$offset.'/qA/'.$new_order, 'qA'),
   anchor('display/index/'.$offset.'/qB/'.$new_order, 'qB'),
   anchor('display/index/'.$offset.'/qC/'.$new_order, 'qC'),
   'Actions'
  );
  $i = 0 + $offset;
  foreach ($querys as $query){
   $this->table->add_row(++$i,
                                                                
          $query->Question,
          $query->qA,
          $query->qB,
          $query->qC,
    anchor('display/view/'.$query->QID,'view',array('class'=>'view')).' '.
    anchor('display/update/'.$query->QID,'update',array('class'=>'update')).' '.
    anchor('display/delete/'.$query->QID,'delete',array('class'=>'delete','onclick'=>"return confirm('Are you sure you want to remove this Question?')"))
   );
  }
  $data['table'] = $this->table->generate();
  
  if ($this->uri->segment(3)=='delete_success')
   $data['message'] = 'The Data was successfully deleted';
  else if ($this->uri->segment(3)=='add_success')
   $data['message'] = 'The Data has been successfully added';
  else
   $data['message'] = '';
  // load view
  $this->load->view('display_view', $data);
}



function view($id){
  // set common properties
  $data['title'] = 'Question Details';
  $data['link_back'] = anchor('display/index/','List Of Questions',array('class'=>'back'));

  // get Question details
  $data['query'] = $this->display_model->get_by_id($id)->row();

  // load view
  $this->load->view('display_view', $data);
}




}

VIEW


Code:
<div class="content">
  <h1>Add/Update/Delete </h1>

  <div class="data">&lt;?php echo $table; ?&gt;</div>
            
              
  <div class="paging">&lt;?php echo $pagination; ?&gt;</div>

  <br />
  &lt;?php echo anchor('display/add/','Add new Question',array('class'=>'add')); ?&gt;
                &lt;?php echo anchor('home/','Return to Dashboard'); ?&gt;
                
</div>

#2
[eluser]ede196620[/eluser]
+++++++++++++++++++++++++++++++++++++

#3
[eluser]ede196620[/eluser]
++++++++++++++++++++++++++++++++++++++++++++++

#4
[eluser]davidMC1982[/eluser]
The view function in your controller does not set $data['table'] and $data['pagination'] hence why $table and $pagination are not available to your view.

#5
[eluser]ede196620[/eluser]
pagination ad data is set in index function i fallowed a tutorial for this and the guy did it this way

#6
[eluser]davidMC1982[/eluser]
The index function will only get called when your url is something like:

http://www.example.com/display/

When your url is something like:

http://www.example.com/display/view/234

the view function is called. Your view function doesn't set the table and pagination variables hence the error.

#7
[eluser]ede196620[/eluser]
i am new to codeigniter and daunt know much can u give me some sample code so i would have an idea how to fix this or something ?

#8
[eluser]davidMC1982[/eluser]
I have no idea what you're trying to achieve. It looks like your view() function is trying to display the details of a question, but you are trying to load the view that displays the list of questions.

Change your view function to:

Code:
function view($id){
  // set common properties
  $data['title'] = 'Question Details';
  $data['link_back'] = anchor('display/index/','List Of Questions',array('class'=>'back'));

  // get Question details
  $data['query'] = $this->display_model->get_by_id($id)->row();

  // load view
  $this->load->view('display_question', $data);
}

Create a new view in your views folder called display_question.php and put this code in it:

Code:
&lt;?php echo print_r($query); ?&gt;

Test it works (you should have the contents of $query on the screen). Now modify the display_question view to make it a proper html page, displaying the data however makes sense to you.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.