[eluser]Unknown[/eluser]
i am a beginner in codeigniter framework. I don`t know how to make a search engine with pagination, I have tried several ways according to the user guide but did not work.
Please help me, because the need for quickly. thanks...
My Controller:
<?php
class Kerko extends CI_Controller {
// function for term
function termin($termi_kerkimit = '')
{
if ($this->input->post('q'))
{
redirect('/kerko/termin/' . $this->input->post('q'));
}
if ($termi_kerkimit)
{
// Load the model and perform the search
$this->load->model('kerkimi_model');
$rezultatet = $this->kerkimi_model->termin($termi_kerkimit);
}
// Render the view, passing it the necessary data
$this->load->view('rezultati_kerkimit', array(
'termi_kerkimit' => $termi_kerkimit,
'rezultatet' => @$rezultatet
));
}
}
MY Model:
<?php
class Kerkimi_model extends CI_Model {
function termin($termi, $start = '0', $results_per_page = '0')
{
// Determine whether we need to limit the results
if ($results_per_page > 0)
{
$limit = "LIMIT $start, $results_per_page";
}
else
{
$limit = "";
}
// ekzekutimi i querit
$sql = "SELECT * FROM articles WHERE body LIKE '%$termi%' $limit";
$query = $this->db->query($sql, array($termi, $termi));
return $query->result();
}
function count_search_results($termi)
{
// Run SQL to count the total number of search results
$sql = "SELECT * FROM articles WHERE body LIKE '%$termi%'";
$query = $this->db->query($sql, array($termi));
return $query->row()->count;
}
}