Welcome Guest, Not a member yet? Register   Sign In
newbie in need of help...
#1

[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>
&lt;form&gt;
  Number of records per page :
  <select name="numrecord">
    <option value="20">20</option>
    <option value="50">50</option>
    <option value="&lt;?php echo $numrows; ?&gt;">all</option>
  </select>
&lt;/form&gt;
<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>
&lt;?php foreach($pse_list as $item):?&gt;
    <tr>
        <td>&lt;?php echo $item->cprice;?&gt;</td>
        <td>&lt;?php echo $item->cpercent;?&gt;</td>
        <td>&lt;?php echo $item->cname;?&gt;</td>
        <td>&lt;?php echo $item->ccode;?&gt;</td>
        <td>&lt;?php echo $item->cvolume;?&gt;</td>
    </tr>
&lt;?php endforeach;?&gt;

<tbody>
</table>
&lt;?php echo $alinks; ?&gt;

&lt;/body&gt;
&lt;/html&gt;

please help.. im stuck.. i
#2

[eluser]Ben Edmunds[/eluser]
There are many ways to do this.

Look up AJAX request, HTTP request, and maybe even JSON.


You'll basically want to do an AJAX request to a controller, passing through how many items (or which items) you want and the controller will return it.




Theme © iAndrew 2016 - Forum software by © MyBB