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

[eluser]Unknown[/eluser]
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:

Code:
<?php

class Pgmlist extends Controller {
    
    function __construct()
    {
        parent::Controller();
        $this->load->helper('url');     //creates a url link
        $this->load->helper('form');
        $this->load->database();
        $this->load->library('session');
      
    }
    
    function index()
    {
      
                $term = $_POST['term'];
            
                if(isset($_POST['term']))
                {
                 $this->session->set_userdata('term', $term);          
                }

                $this->session->userdata('term');
                $newdata = $this->session->userdata('term');
            
    
                 //load pagination class
                $this->load->library('pagination');
                $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>';
          
                $this->pagination->initialize($config);
                        

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

?&gt;



Here's the model:

Code:
&lt;?php

class Search_model extends Model{
    
    function search_model()
    {
        parent::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;            
            }
            $Q->free_result();
            return $data;              
              }

    }//end of search($term)function

    
}
?&gt;


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


Code:
&lt;?php
                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();
       ?&gt;
      
    &lt;?php foreach($result as $row): ?&gt;
    <td>
    &lt;?php echo anchor('pgmlist/programs', $row['programName']); ?&gt;
    </td>
    </tr>
    &lt;?php endforeach; ?&gt;
        
    &lt;?php echo $this->pagination->create_links(); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB