CodeIgniter Forums
$this->db->limit Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->db->limit Problem (/showthread.php?tid=12806)



$this->db->limit Problem - El Forum - 10-31-2008

[eluser]LDMajor[/eluser]
Code:
$this->db->where('to',$this->uri->segment(3));
                $this->db->where('picname',0);
                $qcm=$this->db->get('comments');            
                if ($qcm->num_rows() == 0) {
                    $data['yescomm']=0;
                } else {
                    $data['yescomm']=1;
                    $perpage=10;
                    if ($this->uri->segment(4)) {
                        $page=$this->uri->segment(4);
                    } else {
                        $page=1;
                    }
                    $nump=$qcm->num_rows();
                    $nump = $nump / $perpage;
                    if(intval($nump) != $nump)
                        $data['nump'] = intval($nump) + 1;
                    $lim1 = ($page - 1) * $perpage;
                    $this->db->where('to',$this->uri->segment(3));
                    $this->db->where('picname',0);
                    $this->db->limit($lim1, $perpage);
                    $data['comments']=$this->db->get('comments');
                }
I tested the code and without the LIMIT the code works fine
and with it is doesn't select anything!

please help
Dan.


$this->db->limit Problem - El Forum - 11-01-2008

[eluser]Crimp[/eluser]
I would look at the SQL and see if it makes sense. If it does, I would try running the SQL in a db app or phpMyAdmin against the record set to see if it returns what I expect. If not, I would tweak the actual query to select the records I expect. Then I would go back to the AR code to produce the correct SQL.


$this->db->limit Problem - El Forum - 11-02-2008

[eluser]Thorpe Obazee[/eluser]
run <?php echo $this->db->last_query();?>

this would output the SQL statement. Check the SQL on phpmyadmin or something like it.