php - DWL with INNER JOIN doesn't work when LIMIT applied -
i'm trying create simple pagination using bootpag.js
in order fetch data i've created pdo
script inner join
because need , display user team names table need apply limit
set page selection.
this troublesome code,
session_start(); include_once("../iconnect/handshake.php"); include_once ("../functions/usercheck.php"); if (isset($_request["page"])){ $page_number = filter_var($_post["page"], filter_sanitize_number_int, filter_flag_strip_high); if(!is_numeric($page_number)){die('invalid page number!');} //incase of invalid page number }else{ $page_number = 1; } $perpage = 3; //get current starting point of records $position = (($page_number-1) * $perpage); //data base join team names teams data base $getusers = "select userlogin.*, teams.teamname userlogin inner join teams on teams.tid = userlogin.uteam order uid desc limit :place, :item_per_page"; $getusersquery = $dbconnect -> prepare($getusers); $getusersquery -> bindparam(':place', $position); $getusersquery -> bindparam(':item_per_page', $perpage); $getusersquery -> execute();
i tried same sql in phpmyadmin worked out errors don't know why throwing below error when used php + pdo.
note: duplicate i've been searching site using bindparam
didn't see duplicate , didn't solve issue selected answer did way if marked what
error:
fatal error: uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near ''0', '3'' @ line 1' in ********\fetchuserlist.php on line 27
when in emulation mode (which on default),pdo substitutes placeholders actual data, instead of sending separately.pdo treats every parameter string. result, prepared limit ?,? query becomes limit '0', '3'
invalid syntax causes query fail.
when using bindparam each variables explicitly need set proper param type.
you might need turn off emulation :
$dbconnect->setattribute( pdo::attr_emulate_prepares, false );
then
<?php $getusersquery -> bindparam(':place', $position,pdo::param_int); $getusersquery -> bindparam(':item_per_page', $perpage,pdo::param_int); ?>
Comments
Post a Comment