Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to  make an pagination example.The problem is  sql query .When I try something like this

     $query=$conn->db->prepare("select * from konular limit 3");

Everything is ok code works as intended But When I try something like this nothing happens
   
 $query=$conn->db->prepare("select * from konular limit".$limit.",".$perpage);

 I dont understand what am i doing wrong


What I have tried:

<?php
require     "conn.php";
require "funct.php";
$conn=new conn();
$funct=new funct();
$perpage=2;

$totalCount= $funct->total();
$pageCount=ceil($totalCount/$perpage);

$currentPage=isset($_GET["page"])?(int)$_GET["page"]:"1";

if($_GET["page"]<0){
    $_GET["page"]="1";
}else if($_GET["page"]>$pageCount){
    $_GET["page"]=$pageCount;

}
$limit=($currentPage-1)*$perpage;
$query=$conn->db->prepare("select * from konular limit".$limit.",".$perpage);
$query->execute();
$pages=$query->fetchAll(PDO::FETCH_ASSOC);
foreach ($pages as $key => $value) {
    echo $key;
}
Posted
Updated 5-Feb-19 4:58am
Comments

1 solution

You are missing a space in your string. It should be:
PHP
$query=$conn->db->prepare("select * from konular limit ".$limit.",".$perpage);
                                                      ^ space required after 'limit'
 
Share this answer
 
Comments
Member 3722539 5-Feb-19 11:12am    
you are awesome
Richard MacCutchan 5-Feb-19 11:24am    
No, I just looked at the code, the error was obvious. Try looking a bit of desk-checking and debugging yourself before posting questions here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900