Welcome Guest, Not a member yet? Register   Sign In
How can Do this in Pagination
#1

[eluser]phantom-a[/eluser]
I need to turn this into pagination. This code works, but will display all my results on the same page, I need into pagination..

Code:
$data['query'] = $this->db->query('SELECT * FROM `table` WHERE `category`=1 ORDER BY date');
$this->load->view('my_view', $data);
#2

[eluser]exodus7[/eluser]
From what I can tell you should use
Code:
$this->db->get_where()
instead of:
Code:
$this->db->get()
This would allow you to include a where clause in your sql. So it would look something like this:
Code:
$query = $this->db->get_where('links', array('category' => 1), $num, $offset);

Let us know if this works Smile
#3

[eluser]phantom-a[/eluser]
It works! it works :lol:
The last problem is also I need a ORDER by statment, but still thanks for help.

There is method called get_where_orderby is there?
#4

[eluser]Sumon[/eluser]
You can use
Code:
$this->db->orderby("date" , "asc");
in order to get order by clause.
#5

[eluser]phantom-a[/eluser]
[quote author="Sumon" date="1220788050"]You can use
Code:
$this->db->orderby("date" , "asc");
in order to get order by clause.[/quote]

I've tried that one too, I does not alter the table for reason. I don't think any data is actually getting passed to it.


Well this my complete code. It works 99% except it loads the rows in the wrong order. its showing the oldest one's first, thats I why I want too use ORDER BY and reverse the order, but it does not work. Smile

*controller
Code:
function cgi_proxies() //Loads the cgi_proxies/index.php/go/cgi_proxies
    {  

        //cgi proxy list settings - EDIT THIS
        $data['mybaseurl'] = "http://127.0.0.1"; //set your baseurl like http://www.example.com/  without trailing slash
          $data['title'] = "Proxy Toplinks 0.1Beta - CGIPROXIES List"; //cgi_proxies  page title
        $data['heading'] = "CGI proxies"; // Heading
        //stop editing
        // load pagination class
        $this->load->library('pagination');
        $this->load->model('cgiproxies_model');
        $config['base_url'] = base_url().'index.php/go/cgi_proxies/';
        $config['per_page'] = '5';
        $all_result_set = $this->cgiproxies_model->get_cgiproxies('',$config['per_page'],$this->uri->segment(3));
        $this->db->orderby("datestamp" , "desc");
        $config['total_rows']=$all_result_set['num_rows'];
        $data['results']=$all_result_set['result'];

     // the rest of pagination settings
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);


        
        // load the HTML Table Class
        $this->load->library('table');
        $this->table->set_heading('ID', 'Title', 'Author', 'Description');
        
        // load the view
        $this->load->view('cgi_proxies', $data);

*the model class "cgiproxies_model"
Code:
class cgiproxies_model extends Model {
  function __construct(){
    parent::Model();
  }

function get_cgiproxies($param,$limit=15,$offset){
     $this->db->select('*');
     $data['num_rows'] = $this->db->count_all_results('links');
     $data['result'] = $this->db->get_where('links', array('category' => 1),$limit,$offset);
     $this->db->orderby("datestamp" , "asc");
     return $data;
}
}
#6

[eluser]Sumon[/eluser]
By the way here is my custom pagination. you may try it.
Here is my controller code
Code:
$this->load->model("asknanny_model");//my model

$PerPageRecord=5;
$TotalRecord=$this->asknanny_model->TotalQuestion();//echo $TotalRecord."<br>";
$TotalListing=ceil($TotalRecord/$PerPageRecord);

if($CurListing==0)
{
  $CurListing=1;
  $RecordStart=0;
  $RecordEnd=$PerPageRecord-1;
}
else
{
  $RecordStart=( ($CurListing-1)*$PerPageRecord );    //Index no 40= Record no 41. though start from 0.
  $RecordEnd=$RecordStart+$PerPageRecord-1;
}
if($RecordEnd>$TotalRecord)
  $RecordEnd=$TotalRecord-1;
$Limit="LIMIT $RecordStart, $PerPageRecord";
if($RecordStart+1>$TotalRecord)    $DisplayStartVal=$TotalRecord;
elseif($TotalRecord>0) $DisplayStartVal=$RecordStart+1; else $DisplayStartVal=0;

if($RecordEnd+1>$TotalRecord)    $DisplayEndVal=$TotalRecord;
elseif($TotalRecord>0) $DisplayEndVal=$RecordEnd+1; else $DisplayEndVal=0;

$Data['TotalRecord']=$TotalRecord;
$Data['DisplayStartVal']=$DisplayStartVal;
$Data['DisplayEndVal']=$DisplayEndVal;
$Data['CurListing']=$CurListing;
$Data['TotalListing']=$TotalListing;
$Data['Limit']=$Limit;
$Data['CurPageRecords'] = $this->asknanny_model->RecordsForCurPage($Limit);

Here is the view (only pagination link and record portion)
Code:
Displaying &lt;?=$DisplayStartVal?&gt;-&lt;?=$DisplayEndVal?&gt;&nbsp;out of&nbsp;&lt;?=$TotalRecord?&gt;(Page&lt;? if($TotalRecord>0) echo $CurListing; else echo "0";?&gt;)

Page List : <b>
&lt;?php
    for($Listing=1;$Listing<=$TotalListing;$Listing++)
    if($Listing==$CurListing)
    {
        if($TotalListing==$Listing) echo "Last";
        else if($Listing==1)echo "First";
        else echo $Listing;
    }
    else
    {
?&gt;
      <a href="&lt;?=base_url()?&gt;asknanny/AskQuestion/&lt;?=$Listing?&gt;">&lt;? if($TotalListing==$Listing) echo "Last"; else if($Listing==1)echo "First";else echo $Listing;?&gt;</a>
&lt;?  }    ?&gt;
    </b>

I shall highly appreciate if i get some feedback of this pagination.
#7

[eluser]phantom-a[/eluser]
I'm not sure what I do with your pagination. I"m not seasoned programer that doesn't make any sense to me barely. I am only a little green in php as the moment..
#8

[eluser]Sumon[/eluser]
i am really sorry. the time when i write pagination post, you write your third reply. sorry i post late and have not check before posting.
#9

[eluser]phantom-a[/eluser]
It appears I solved my problem. You can join methods so I put

Code:
$data['result'] = $this->db->order_by('datestamp','desc')->get_where('links', array('category' => 1),$limit,$offset);

and now it works , showing the newest first, where category=1 Smile
#10

[eluser]Sumon[/eluser]
Lets have a close look the following line of codes

Code:
$all_result_set = $this->cgiproxies_model->get_cgiproxies('',$config['per_page'],$this->uri->segment(3));
$this->db->orderby("datestamp" , "desc");
$config['total_rows']=$all_result_set['num_rows'];
$data['results']=$all_result_set['result'];

Seems to me you have written $this->db->orderby("datestamp" , "desc"); in wrong place. Try to place it in model function get_cgiproxies(......

Let us know what's going on..




Theme © iAndrew 2016 - Forum software by © MyBB