[eluser]megamonk[/eluser]
hi ive been practicing CI lately and im stuck...
basically what i want to do is be able to change the number of rows of my table depending on the dropdown menu value without reloading the page... i was thinking of re-running the controller then change the $perpage variable but i dont even know if that is possible...
here is my model
Code:
<?php
class Mmain extends Model {
function Mmain()
{
// Call the Model constructor
parent::Model();
}
function get_pse($offset, $range)
{
$query = $this->db->query('SELECT * FROM psedata LIMIT '.$offset.', '.$range.'');
return $query->result();
}
function get_psef()
{
return $this->db->count_all_results('psedata');
}
}
?>
my controller
Code:
<?php
class Cmain extends Controller {
function index()
{
$this->load->helper('url');
$this->load->database();
$this->load->model('mmain');
$this->load->library('pagination');
$page_segment = $this->uri->segment(3,0);
//must be updated via ajax then re-run the query to fill new set of data
$perpage = 20;
////////////////////////////////////////////////////////////////////////
$config['base_url'] = site_url('cmain/index');
$config['uri_segment'] = 3;
$data['pse_list'] = $this->mmain->get_pse($page_segment,$perpage);
$numrows = $this->mmain->get_psef();
$config['total_rows'] = $numrows;
$config['per_page'] = $perpage;
$this->pagination->initialize($config);
$data['alinks'] = $this->pagination->create_links();
$data['title'] = "My Test";
$data['numrows'] = $numrows;
//print_r ($data);
$this->load->view('nmain', $data);
}
}
?>
my view
Code:
<html>
<head>
<title><?php echo $title; ?></title>
[removed][removed]
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/mycss.css" />
</head>
<body>
<p>Date:</p>
<form>
Number of records per page :
<select name="numrecord">
<option value="20">20</option>
<option value="50">50</option>
<option value="<?php echo $numrows; ?>">all</option>
</select>
</form>
<table class="sortable">
<thead>
<tr>
<th>Price</th>
<th>Percent Change</th>
<th>Company Name </th>
<th>Company Code </th>
<th>Volume</th>
</tr>
</thead>
<tbody>
<?php foreach($pse_list as $item):?>
<tr>
<td><?php echo $item->cprice;?></td>
<td><?php echo $item->cpercent;?></td>
<td><?php echo $item->cname;?></td>
<td><?php echo $item->ccode;?></td>
<td><?php echo $item->cvolume;?></td>
</tr>
<?php endforeach;?>
<tbody>
</table>
<?php echo $alinks; ?>
</body>
</html>
please help.. im stuck.. i