[eluser]Corbee[/eluser]
Hi,
I have a page(a) that calls another page(b) to display the data, the problem is that the data submitted by page(a) to page(b) can't be read by the paginated form. I tried to session the posted data, but it wasn't helpful at all.
Here is the code.
Controller
Code:
class Manage extends controller
{
function index()
{
$data['title']='System Manager';
$data['main'] = 'admin_manage_home';
$data['carbrand']= $this->MManage->getcarbrand();
$data['year']= $this->MManage->getcaryear();
$this->load->view('dashboard',$data);
}
function vehicle()
{
$this->load->library('pagination');
$data['title'] ='Vehicle Management';
$data['main'] = 'admin_manage_cars';
$config['base_url'] = base_url().'index.php/manage/vehicle';
$config['total_rows'] = $this->db->count_all('carmodel');
$config['per_page'] = '15';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
//load the model and get results
$data['vehicle'] = $this->MManage->getvehicle($config['per_page'],$this->uri->segment(3));
$this->load->view('dashboard',$data);
}
}
Model:
Code:
class MManage extends Model
{
function __construct()
{
parent::Model();
}
function getvehicle($num='',$offset='')
{
$_SESSION['year'] =$_POST['year'];
$_SESSION['brand'] = $_POST['brand'];
$year= $_SESSION['year'];
$brandID = $_SESSION['brand'];
$data = array();
//$this->db->select('modelName,carbrand.brandName,carbrand.logo');
$this->db->from('carModel');
$this->db->join('caryear','caryear.modelID=carmodel.modelID','left');
$this->db->join('carbrand','caryear.brandID=carbrand.brandID','left');
$this->db->where('year',$year);
$this->db->limit($num,$offset);
$q = $this->db->get();
if ($q->num_rows() > 0)
{
foreach ($q->result_array() as $row)
{
$data[] = $row;
}
}
$q-> free_result();
return $data;
}
function getcarbrand()
{
$this->db->distinct();
$this->db->from('carmodel');
$this->db->join('carbrand','carbrand.brandID=carmodel.brandID','left');
$this->db->where('carbrand.brandID IS NOT NULL');
return $this->db->get();
}
function getcaryear()
{
return $this->db->get('caryear');
}
}
Views:
page(a) - admin_manage_home
Code:
<form action="manage/vehicle" method="post">
<fieldset>
<legend>Administer Vehicle</legend>
<p>
<div class="tab1">
<label for="year">Year:</label>
<?php //populating the year
if ($year->num_rows() > 0)
foreach($year->result_array() as $rows)
{
$options[$rows['year']]=$rows['year'];
}
echo form_dropdown('year',$options);
?>
<label for="brand">Brand:</label>
<?php //populating the brand
if ($carbrand->num_rows() > 0)
foreach($carbrand->result_array() as $rows)
{
$options1[$rows['brandID']]=$rows['brandName'];
}
echo form_dropdown('brand',$options1);
?>
</p>
<div class="tab"><div class="tab"><p><?php echo anchor('manage/addvehicle','Add a New Vehicle'); ?> or <input type="submit" value="Go"/></p></div></div></div>
</fieldset>
</form>
page(b) - admin_manage_cars
Code:
<?php
echo '<p>';
if ($this->session->flashdata('message')){
echo "<div class='message'>".$this->session->flashdata('message')."</div>";
}
if (count($vehicle))
{
echo "<table border='1' cellspacing='0' cellpadding='3' width='400' > \n";
echo " <tr valign='top' > \n";
echo " <th>Year</th><th>Model Name</th><th>Type</th><th>Actions</th>\n";
echo " </tr>";
foreach ($vehicle as $key => $list)
{
echo "<tr valign='top'>";
echo "<td>".$list['year']."</td>";
echo "<td> ".$list['modelName']."</td>";
echo "<td> ".$list['carType']."</td>";
echo "<td align='center'>";
echo anchor('vehicle/edit/'.$list['caryearID'],'edit');
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>";
}
echo $this->pagination->create_links();
echo '</p>';
?>
By the way, here is the error output when you used the pagination links
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: year
Filename: models/mmanage.php
Line Number: 12
A PHP Error was encountered
Severity: Notice
Message: Undefined index: brand
Filename: models/mmanage.php
Line Number: 13