K finally got it i was just thinking in terms of using the table id to do the next/prev calcuations.
anyways, i got date working but there is alot more involved, in terms of < > and desc and acs.. here is my code so far, remeber i have only debuged date so the others are a work in progress (for anyone else look for an anwser to this problems)
function GetNextPrev($mbox,$mid)
{
global $GLOBAL_USER_NAME;
global $GLOBAL_USER_SORT_ORDER;
global $GLOBAL_USER_SORT_BY;
#mid consists of the <DATE_MID> in it
$mdate = $this->filetomysqldate($mid,0,strpos($mid,""));
$xmid = substr($mid,strpos($mid,"")+1,strlen($mid));
--- get the info about the message
$q = "SELECT mfrom,msubject,msize from mail_listing.$GLOBAL_USER_NAME WHERE mid='$xmid' AND mdate='$mdate'";
$q = mysql_query($q,$this->DBconnectid);
if (mysql_num_rows($q) == 0) { $this->ErrorMessage = "Message not found in NextPrev"; return FALSE; }
$mfrom = mysql_result($q,0,'mfrom');
$msubject = mysql_result($q,0,'msubject');
$msize = mysql_result($q,0,'msize');
-- make the next/prev SQL statements depending on the sort type
if ($GLOBAL_USER_SORT_ORDER == 'dsc') {
$qo = ' DESC'; $qx = ' ASC'; $qn = "<"; $qp = ">"; } else {
$qo = ' ASC'; $qx = ' DESC'; $qn = ">"; $qp = "<"; }
if ($GLOBAL_USER_SORT_BY == 'from') {
$qnext = "mfrom>'$mfrom' ORDER BY mfrom";
$qprev = "mfrom<'$mfrom' ORDER BY mfrom"; }
elseif ($GLOBAL_USER_SORT_BY == 'subj') {
$qnext = "msubject>'$msubject' ORDER BY msubject";
$qprev = "msubject<'$msubject' ORDER BY msubject"; }
elseif ($GLOBAL_USER_SORT_BY == 'size') {
$qnext = "msize>'$msize' ORDER BY msize";
$qprev = "msize<'$msize' ORDER BY msize"; }
else {
$qnext = "mdate $qn '$mdate' ORDER BY mdate";
$qprev = "mdate $qp '$mdate' ORDER BY mdate";
$qend = " ORDER BY mdate"; }
$qbase = "SELECT mdate,mid,msubject FROM mail_listing.$GLOBAL_USER_NAME ";
$qgo = $qbase . "WHERE mbox='$mbox' AND " . $qnext . $qo . " LIMIT 1";
echo "NEXT - $qgo<BR>";
$q = mysql_query($qgo,$this->DBconnectid);
if (mysql_num_rows($q) == 0) {
#At the end of the records so get the 1st
$qgo = $qbase . $qend . $qo . " LIMIT 1";
echo "NEXT - $qgo<BR>";
$q = mysql_query($qgo,$this->DBconnectid);
if (mysql_num_rows($q) == 0) { $this->ErrorMessage = "Message not found in (next) on get 1st"; return FALSE; } }
#set the end user MID for the next/prev button in view.php
$this->MidNext = $this->mysqltofiledate(mysql_result($q,0,'mdate')) . "_" . mysql_result($q,0,'mid');
$qgo = $qbase . "WHERE mbox='$mbox' AND " . $qprev . $qx . " LIMIT 1";
echo "PREV - $qgo<BR>";
$q = mysql_query($qgo,$this->DBconnectid);
if (mysql_num_rows($q) == 0) {
#At the end of the records so get the last
$qgo = $qbase . $qend . $qx . " LIMIT 1";
echo "PREV - $qgo<BR>";
$q = mysql_query($qgo,$this->DBconnectid);
if (mysql_num_rows($q) == 0) { $this->ErrorMessage = "Message not found in (prev) on get 1st"; return FALSE; } }
$this->MidPrev = $this->mysqltofiledate(mysql_result($q,0,'mdate')) . "_" . mysql_result($q,0,'mid');
return TRUE;
}