Jump to content

Recommended Posts

Hey guys.

I've been using pagination alot. However recently i've decided to create

a class. The class contains a function to collect the items from a database.

 

Everything works fine until i use LIMIT $x,$y. kinda thing. then i get the following error

Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11.

 

My php page is. (this is the snipper which is needed.)

$cpage =(!$_GET[p])? 1:$_GET[p];
$template_nav = $template->assign_navigation($cutom_folders);
$page_info.= $template->pm_reminder($estarray);
$page_info.= $messenger->inbox;
$page.= $messenger->collect_items($cpage,$messenger->pmpagelimit);
if($messenger->inbox_items()){
	#while($item = $messenger->collect_items()){
	#	$page.= "test";
	#}
}
$page.= "inbox";

 

this is my class function..

function collect_items($page,$limit){
	$sql = mysql_query("select `pmid`, `pmauthor`, `pmsubject`, `pmsubmitted`, `pmstatus`,
	case when `pmstatus`='0' then 1 
	when `pmstatus`='1' then 2 
	else 3 
	end as `pmsort`
	from `".$this->tbl."messenger` 
	where `pmrecipient`='".$_SESSION[$this->session]."' 
	and `pmdeleted`='0'
	and `pmfolderid`='0'
	order by `pmsort`,`pmsubmitted` desc
	limit $page,$tlimit") or trigger_error(mysql_error(),E_USER_ERROR);
	return mysql_fetch_array($sql);
}

 

However if i use this. the error will no show-up.

function collect_items($page,$limit){
	$sql = mysql_query("select `pmid`, `pmauthor`, `pmsubject`, `pmsubmitted`, `pmstatus`,
	case when `pmstatus`='0' then 1 
	when `pmstatus`='1' then 2 
	else 3 
	end as `pmsort`
	from `".$this->tbl."messenger` 
	where `pmrecipient`='".$_SESSION[$this->session]."' 
	and `pmdeleted`='0'
	and `pmfolderid`='0'
	order by `pmsort`,`pmsubmitted` desc") or trigger_error(mysql_error(),E_USER_ERROR);
	return mysql_fetch_array($sql);
}

Link to comment
https://forums.phpfreaks.com/topic/79127-solved-unknown-mysql-limit-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.