PDA

View Full Version : Pagination with emails



nuttycoder
09-15-2008, 04:24 PM
Hi,

am building an email program web based using the imap functions am wondering is it possible to limit how many emails their is per page?
I have looked at the imap functions but cannot find any mention of limiting the list.

I could do this if I stored all the emails in a database but I'd rather just grab the emails straight from the server and then show say 30 per page.

here my code to print out all the emails:




<table class="stripeMe">
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<tr>
<th>&nbsp;</th>
<th><a href="index.php?order=subject"><b>Subject</b></a></th>
<th><a href="index.php?order=from"><b>From</b></a></th>
<th><a href="index.php?order=date"><b>Date</b></a></th>
<th><a href="index.php?order=size"><b>Size</b></a></th>
</tr>



<?php

$orderReg = $_GET['order'];

switch ($orderReg) {
case "date":
$orderby = SORTARRIVAL;
break;
case "from":
$orderby = SORTFROM;
break;
case "subject":
$orderby = SORTSUBJECT;
break;
case "size":
$orderby = SORTSIZE;
break;
default:
$orderby = SORTARRIVAL;
}


// sort the messages by subject
$sorted = imap_sort($mbox, $orderby, 1);

if($total == 0)
{
echo "<tr><td>No Emails in {$_SESSION['folder']}</td></tr>";
}

// display again
for ($i=0; $i<count($sorted); $i++) {
$header = imap_header($mbox, $sorted[$i]);


?>
<tr>
<td align="right" valign="top"><input type="checkbox" name="del[]" value="<?php echo trim($header->Msgno); ?>"></td>
<td valign="top"><a href="<?php echo $dir;?>view-<?php echo trim($header->Msgno);?>">


<?php if(trim($header->Subject) !== ''){

if($header->Unseen == 'U')
{
echo "<b>$header->Subject</b>";
}
else { echo $header->Subject; }}
else { echo "No Subject";
}
?>
</a></td>
<td valign="top"><?php echo $header->fromaddress;?></td>
<td valign="top"><?php echo date('d/m/Y h:m:s',strtotime($header->date));?></td>
<td valign="top"><?php echo ceil(($header->Size /1024)), " KB";?></td>
</tr>
<?php } ?>
</form>


any help would be great cheers.