Welcome Guest, Not a member yet? Register   Sign In
Search Result and Pagination Error

Hi everyone.
I'm quite new to programming and having a hard time doing this application. Ive been reading a lot of the topics here regarding searches and pagination, but i just cant seem to do it right. Can someone please help me? I would really appreciate it! :cheese:

Im doing a search engine displaying the program names. The search function is working but whenever the query reaches the page limit (example 10) and clicked the page 2 button of the pagination link, the items from my database are shown instead of the 2nd page from query result. Also, there's an error that says that theres an Undefined index, which is the $term (search keyword). BTW, Im using MS SQL.

Here's the controller:


class Pgmlist extends Controller {
    function __construct()
        $this->load->helper('url');     //creates a url link
    function index()
                $term = $_POST['term'];
                 $this->session->set_userdata('term', $term);          

                $newdata = $this->session->userdata('term');
                 //load pagination class
                $config['base_url'] = base_url().'index.php/pgmlist/index/'.$term;
                $config['total_rows'] = $this->db->count_all('saiyo');
                $config['per_page'] = '10';
                $config['full_tag_open'] = '<p>';
                $config['full_tag_close'] = '</p>';

                 //load model and get result
                 $data['result'] = $this->search_model->get_programs($term,  $config['per_page'], $this->uri->segment(3, 0));
                //load the HTML table class
                 $this->load->view('pgmlist_view', $data);  
}//end of controller


Here's the model:


class Search_model extends Model{
    function search_model()
    }//end of search_model function

    function get_programs($term, $num, $offset)
       $sql = "Select TOP $num * from saiyo
        where programName not in
        (select top $offset programName from saiyo WHERE programName LIKE '%%$term%%' ) and programName
        like '%%$term%%' ";
       $Q = $this->db->query($sql);

        if ($Q->num_rows() > 0){
            foreach($Q->result_array() as $row)
                $data[] = $row;            
            return $data;              

    }//end of search($term)function


The view:
(the following are only parts of the view)

                echo form_open('pgmlist/index');
                $data1 = array(
                   'name' => 'term',
                   'id' => 'term',
                   'maxlength' => '50',
                   'size' => '50',
                   'style' => 'background-color:#f1f1f1'
                echo form_input($data1);
                echo form_submit('submit', 'search');
                echo form_close();
    &lt;?php foreach($result as $row): ?&gt;
    &lt;?php echo anchor('pgmlist/programs', $row['programName']); ?&gt;
    &lt;?php endforeach; ?&gt;
    &lt;?php echo $this->pagination->create_links(); ?&gt;

Theme © iAndrew 2016 - Forum software by © MyBB