Jump to content
MakeWebGames

Adding Pages to Mail and Events


Smokey

Recommended Posts

Ok, so I'm trying to add pages to mails and events (well mails to start with) and I am having some troubles with the database queries.

This is what I have so far:

 

$mcnt=mysql_query("SELECT * FROM mails");
$mails=mysql_num_rows($mcnt);
$pages=(int) ($mails/25)+1;
if($mails % 100 == 0)
{
$pages--;
}
echo "<center>Pages: ";
for($i=1;$i <= $pages;$i++)
{
$stl=($i-1)*25;
echo "<a href='mailbox.php?st='>$i</a>";
}

 

Of course I know the top query and the mailbox echo are incorrect and I'm pretty sure something else is missing, but I'm not sure what they should be, if someone could help it would be much appreciated, I'm hitting a wall with this.

Link to comment
Share on other sites

Thats what I'm trying to do, this excerpt was taken from the userlist and altered.

$cnt=mysql_query("SELECT userid FROM users",$c");

thats the query from the userlist, i took the ,$c out as its not needed.

I tired:

$mcnt=mysql_query("SELECT mail_text FROM mails);

$mcnt=mysql_query("SELECT mail_id FROM mails");

$mcnt=mysql_query("SELECT * FROM mails");

and none worked.

More importantly I cannot figure out how to flip pages,

<a href='mailbox.php?st='>$i</a>";

This is wrong and I have no idea how to make it work so it will flip to another page

Link to comment
Share on other sites

I tried that but couldnt get it to work correctly, the 3 pagination functions, the reason being is because I don't know how to get the correct info from the database to build the pages, and for the pagination functions you need to have that done, which is what I am asking for help with lol.

Link to comment
Share on other sites

This should help you workd on MCv2

add to global_func.php

 

function pager($rpp, $count, $href, $opts = array()) {
 $pages = ceil($count / $rpp);

 if (!$opts["lastpagedefault"])
   $pagedefault = 0;
 else {
   $pagedefault = floor(($count - 1) / $rpp);
   if ($pagedefault < 0)
     $pagedefault = 0;
 }

 if (isset($_GET["page"])) {
   $page = 0 + $_GET["page"];
   if ($page < 0)
     $page = $pagedefault;
 }
 else
   $page = $pagedefault;

 $pager = "";

 $mp = $pages - 1;
 $as = "<b>« Prev</b>";
 if ($page >= 1) {
   $pager .= "<a href=\"{$href}page=" . ($page - 1) . "\">";
   $pager .= $as;
   $pager .= "</a>";
 }
 else
   $pager .= $as;
 $pager .= "      ";
 $as = "<b>Next »</b>";
 if ($page < $mp && $mp >= 0) {
   $pager .= "<a href=\"{$href}page=" . ($page + 1) . "\">";
   $pager .= $as;
   $pager .= "</a>";
 }
 else
   $pager .= $as;

 if ($count) {
   $pagerarr = array();
   $dotted = 0;
   $dotspace = 3;
   $dotend = $pages - $dotspace;
   $curdotend = $page - $dotspace;
   $curdotstart = $page + $dotspace;
   for ($i = 0; $i < $pages; $i++) {
     if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
       if (!$dotted)
         $pagerarr[] = "...";
       $dotted = 1;
       continue;
     }
     $dotted = 0;
     $start = $i * $rpp + 1;
     $end = $start + $rpp - 1;
     if ($end > $count)
       $end = $count;
     //$text = "$start - $end";
     $text = ($i + 1);
     if ($i != $page)
       $pagerarr[] = "<a href=\"{$href}page=$i\"><b>$text</b></a>";
     else
       $pagerarr[] = "<b>$text</b>";
   }
   $pagerstr = join(" | ", $pagerarr);
   $pagertop = "<p style=\"text-align: center;\">$pager<br />$pagerstr</p>\n";
   $pagerbottom = "<p style=\"text-align: center;\">$pagerstr<br />$pager</p>\n";
 }
 else {
   $pagertop = "<p style=\"text-align: center;\">$pager</p>\n";
   $pagerbottom = $pagertop;
 }

 $start = $page * $rpp;

 return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
}

 

Now on your mailbox.php if you havent made any edits to function mail_inbox() then overwrite with this one.

 

function mail_inbox()
{
global $db,$ir,$c,$userid,$h;
print<<<END
<SCRIPT><!-- HIDE
function setCheckboxes(the_form, do_check) {
   var elts      = (typeof(document.forms[the_form].elements['ID[]']) != 'undefined')
                 ? document.forms[the_form].elements['ID[]']
                 : (typeof(document.forms[the_form].elements['ID[]']) != 'undefined')
         ? document.forms[the_form].elements['ID[]']
         : document.forms[the_form].elements['ID[]'];
   var elts_cnt  = (typeof(elts.length) != 'undefined')
                 ? elts.length
                 : 0;
   if (elts_cnt) {
       for (var i = 0; i < elts_cnt; i++) {
           elts[i].checked = do_check;
       } // end for
   } else {
       elts.checked        = do_check;
   } // end if... else
   return true;
}
// STOP HIDING --></SCRIPT>
END;
$res = mysql_query("SELECT COUNT(*) FROM mail WHERE mail_to=$userid") or die(mysql_error());
$row = mysql_fetch_array($res);
$count = $row[0];

$addparam = "";

list($pagertop, $pagerbottom, $limit) = pager(2, $count, "mailbox.php?" . $addparam);
$query = "SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_to=$userid ORDER BY mail_time DESC $limit";
$res = mysql_query($query) or die(mysql_error());
$i=0;
echo "<p style=\"text-align: center;\">Mail Sorted By Newest.</p>
$pagertop";
echo "<table style=\"margin: 0 auto 0 auto; border: solid #292929 0px; width: 90%;\">
<tr class=tablecellheader><td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">Subject</p></td>
<td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">From</p></td>
<td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">Status</p></td>
<td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">Received</p></td>
<td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">Read</p></td>
<td><p style=\"margin: 0 0 0 0; font-weight: bold; color: #ffffff;\">Delete</p></td></tr>";
while ($r = mysql_fetch_array($res))
{
if (!$i) {
   $bg = "#ffffff";
   $i = 1;
 }
 elseif ($i) {
   $bg = "#ececec";
   $i = 0;
 }
 if ($r[mail_subject] == "") {
 echo "<tr style=\"background-color: $bg;\"><td><p style=\"margin: 0 0 0 0;\">NO SUBJECT</p></td>
 <td><p style=\"margin: 0 0 0 0;\"><a href=\"viewuser.php?u=$r[userid]\">".$r[username]."</a></p></td>";
 }
 else
  echo "<tr style=\"background-color: $bg;\"><td><p style=\"margin: 0 0 0 0;\">$r[mail_subject]</p></td>
 <td><p style=\"margin: 0 0 0 0;\"><a href=\"viewuser.php?u=$r[userid]\">".$r[username]."</a></p></td>";
 if($r['mail_read'] == 1)
{
echo"<td><p style=\"margin: 0 0 0 0;\"><font color=green>Opened</font></p></td>";
}
else
{
echo"<td><p style=\"margin: 0 0 0 0;\"><font color=red>Un-Opened</font></p></td>";
}
echo"<td><p style=\"margin: 0 0 0 0;\">".$sent=date('F j, Y, g:i:s a',$r['mail_time'])."</p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=read&ID={$r['mail_id']}'>View</a></p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=delete&ID={$r['mail_id']}'>
Delete
</a><form name='masssell' method=post action=mailbox.php?action=del><input type='checkbox' name='del$i' value='yes'>
<input type='hidden' name='id$i' value='{$r['mail_id']}'></td>";

$i++;
//$fm=$r['mail_subject'];
}
echo "<br />";
print<<<END
<tr>
<td colspan=5 align=center>
<input name=sellmass type=submit id=sellmass value='Delete selected'><a href=# onClick="setCheckboxes('masssell',true); return false;'><br>
Check All</A> | <a href=# onClick="setCheckboxes('masssell',false); return false;">Uncheck All</A>
</form>
</td>
</tr>
</table>
END;
echo "$pagerbottom";
}

 

add a bit of CSS to header which is

.tablecellheader{

background-color:#0de0de;

}

On this script change list($pagertop, $pagerbottom, $limit) = pager(2, $count, "mailbox.php?" . $addparam); the 2 to the number of mails to show per page

Edited by illusions
Link to comment
Share on other sites

That almost works, lol, for some reason when you click to view a mail, the page just refreshes, it doesn't open the mail. If you arent on the first page it just refreshes and goes back to the first page. I've edited my mailbox quite a bit, so I adapted it in. And since it wouldn't open the mails I went back to my stock mailbox.php file, and then added it, got the same thing, the mail wont open, it just refreshes the page. Delete also doesnt work, does the same thing, I'm going to work on it some more tomorrow and see if i can combine my mailbox and this one, so that I will have pages but not have to open the mail OR find out why it wont view or delete.

I'm guessing it has something to do with this section:

 

echo"<td><p style=\"margin: 0 0 0 0;\">".$sent=date('F j, Y, g:i:s a',$r['mail_time'])."</p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=read&ID={$r['mail_id']}'>View</a></p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=delete&ID={$r['mail_id']}'>
Delete
</a><form name='masssell' method=post action=mailbox.php?action=del><input type='checkbox' name='del$i' value='yes'>
<input type='hidden' name='id$i' value='{$r['mail_id']}'></td>";

Or possibly the printed section below it.

Link to comment
Share on other sites

That almost works, lol, for some reason when you click to view a mail, the page just refreshes, it doesn't open the mail. If you arent on the first page it just refreshes and goes back to the first page. I've edited my mailbox quite a bit, so I adapted it in. And since it wouldn't open the mails I went back to my stock mailbox.php file, and then added it, got the same thing, the mail wont open, it just refreshes the page. Delete also doesnt work, does the same thing, I'm going to work on it some more tomorrow and see if i can combine my mailbox and this one, so that I will have pages but not have to open the mail OR find out why it wont view or delete.

I'm guessing it has something to do with this section:

 

echo"<td><p style=\"margin: 0 0 0 0;\">".$sent=date('F j, Y, g:i:s a',$r['mail_time'])."</p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=read&ID={$r['mail_id']}'>View</a></p></td>
<td><p style=\"margin: 0 0 0 0;\"><a href='mailbox.php?action=delete&ID={$r['mail_id']}'>
Delete
</a><form name='masssell' method=post action=mailbox.php?action=del><input type='checkbox' name='del$i' value='yes'>
<input type='hidden' name='id$i' value='{$r['mail_id']}'></td>";

Or possibly the printed section below it.

Strange it worked flawlessly when i was testing it...

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...