PDA

View Full Version : Basic pagination


deveray
11-03-2007, 04:12 AM
Below is a page in desparate need of pagination. I am leaving out some of the code, as the file is 7 pages long (Well, most of it ended up here anyway).

In the second post, I will paste in parts (most) of another page from the same site that already has pagination. The one below and needing pagination is the private mail inbox folder. The other one used for reference is the search by name results. My SENT Mail folder and Instant Message results need pagination also. But I figure if getting just one of them locked in, I may be able to transfer the knowedge over, given the same or very similar query string being fairly likely.

If anyone knows how to help get that function installed on the mail page, it sure would make life easier for people who are now waiting on 200 or so messages (up to many hundreds) to load each time checking for new mail. Oh, by the way, the current pagination (shown on the second post) is VERY limited in that it only offers a total, and then a single link for advancing another 25 rows.

So getting one with actual pages listed, such as:


First 4 5 6 7 --- 18 29 20 21 Last


... will not lead to a complaint from moi. But I will be thrilled to even get at least what is available on the search new user results page.


Currently, it looks like this:

Previous 25 --- Next 25


Anyway, the files. If the request is way too much for asking help with, I will understand. Otherwise, great, maybe I get to solve an inherited and dreadful shortcoming on the custom made (by someone else) website.




<head><title>MeetChristians.com - Private Messages</title></head>


VMD View Mail Deleted or View Mail I've Deleted
SML See Mail or My Inbox
SMS See Mail Sent or View Mail I've Sent
QMR Quick Message Review or View Quick Message History


<?php

$inc_dir ="./incl";
require "$inc_dir/nav_bar.inc.php";
require "$inc_dir/mail.inc.php";



if ($sml != "")
{
$sml="T";
$w = "waiting.";
}

if ($vmd != "")
{
$sml="";
$vmd="T";
$d = "deleted ";
$del="&del=T";
}

mail_options($sml, $vmd, $sms, $qmr, $tdy);

if ($sex == "M")
{
$msg_table = "M_msg";
}
elseif ($sex == "F")
{
$msg_table = "F_msg";
}

$and_condition = "AND deleted != 'Y'";

$query = "SELECT id, m_to, m_from, subject, DATE_FORMAT(sent_d, '%b %e, %Y'), if_read, replied, deleted, message, gto, gfr, to_id, TIME_FORMAT(sent_t, '%H:%i'), read_d, ers, d
FROM $msg_table
WHERE m_to = '$session_username' $and_condition
ORDER BY id DESC liMIT 100"; // added limit 102507
if ($vmd != "")
{
$and_condition = "AND deleted = 'Y'";
$query = "SELECT id, m_to, m_from, subject, DATE_FORMAT(sent_d, '%b %e, %Y'), if_read, replied, deleted, message, gto, gfr, to_id, TIME_FORMAT(sent_t, '%H:%i'), read_d, ers, d
FROM $msg_table
WHERE m_to = '$session_username' $and_condition
ORDER BY id DESC";
}
$result = mysql_db_query($db, $query);

$rows = mysql_num_rows($result);


if ($rows == 1)
{
$message_plural = "message";
}
else
{
$message_plural = "messages";
}
if ($rows < 1)
{
no_mail_message($vmd);
}

print "<form action=m_delete.php>
<input type=hidden name=tdy value=$tdy>



<center>

<font face=tahoma size=2>
<table bgcolor=gray cellpadding=5 border=4 bordercolorlight=#e6e6cd bordercolordark=#333333>
<tr>
<td>

<font color=yellow><b>You have <font color=cyan>$rows <font color=yellow>$d $message_plural $w</b>

</td>
</td>
</table>



<TABLE cellSpacing=0 cellPadding=0 width=725 border=0>
<TR>
<TD>

<table width=100% borderColor=#666666 borderColorLight=#BBBBBB border=1 cellspacing=0 cellpadding=2>

<tr ALIGN=CENTER VALIGN=CENTER BGCOLOR=#0000DD>";

if ($vmd == "T")
{

print "

<td width=20%><b><font face=Arial,Helvetica color=white size=2>To</b></td>";
}
else
{
print "
<td width=20%><b><font face=tahoma color=cyan size=3>From</b></td>";
}

if ($vmd != "T")
{
print "
<td width=5%><b><font face=tahoma color=cyan size=3>Select</b></td>";
}

print "

<td><b><font face=tahoma color=cyan size=3>Subject</b></td>
<td><b><font face=tahoma color=cyan size=3>Status</b></td>
<td><b><font face=tahoma color=cyan size=3>Sent</b></td>

</tr>";

while ($row=mysql_fetch_row($result))
{
$id=$row[0];
$m_to=$row[1];
$m_from=$row[2];
$subject=$row[3];
$sent_d=$row[4];
$if_read=$row[5];
$replied=$row[6];
$deleted=$row[7];
$message=$row[8];
$gto=$row[9];
$gfr=$row[10];
$to_id=$row[11];
$sent_t=$row[12];
$read_d=$row[13];
$ers=$row[14];
$d=$row[15];
$status = "<b><font color=red>NEW<font color=black></b>";

if ($if_read == "Y")
{
$status = "<font color=mediumvioletred>Viewed</font>";
}
if ($replied != "")
{
$status = "Replied";
}
if ($deleted == "Y")
{
$status = "$status and Deleted";
}
$if_donated = "";
if ($d == "Y")
{
$if_donated = "<font size=5 color=gold>&nbsp;<b>*</b>";
}


print "


<tr ALIGN=CENTER VALIGN=CENTER bgcolor=steelblue>
<td><font face=arial size=-1><b>

<a href=focus.php?tdy=$tdy&name=$m_from&g=$gfr class=donkey>$m_from</a> $if_donated</b></td>";
$msg_lnk = "<a href=m_read.php?tdy=$tdy&id=$id&gfr=$gfr$del class=donkey>";


if ($deleted != "Y")
{

print "

<td valign=center bgcolor=lightsteelblue><font face=arial size=-2><input type=checkbox name=item_to_delete[] value=$id></td>";
}

print "

<td><font face=arial size=-1><b>$msg_lnk$subject</a></td>
<td bgcolor=powderblue><font face=arial size=-1>$status</td>
<td><font face=arial size=-1 color=greenyellow>$sent_d at $sent_t</td>
</tr>";

}

table_footer();




if ($sml != "")
{
print "

<br>

<form>

<table width=725 cellpadding=4 cellspacing=5>
<tr>
<td bgcolor=red>

<INPUT TYPE = submit NAME = delete_mail_button VALUE = \"Delete checked Message(s)\">

</td>

<td bgcolor=#8a2be2> <!-- blueviolet -->

<INPUT TYPE = submit NAME = send_mail_button VALUE = \"Send checked Message(s) to my real email address\">

</td>
</tr>
</table>
</form>

";
}





############################################
# NO MAIL MESSAGE #
############################################
function no_mail_message($vmd) #formerly no hits message
{
if ($vmd == "T")
{
$bgcolor = "#FFFF80";
$no_mail = "Sorry, I can't find any mail you've deleted";
}
else
{
$bgcolor = "pink";
$no_mail = "Sorry, you don't have any new mail";
}

print "
<center><table width=60% bgcolor=$bgcolor>
<tr><td align=center><font face=arial size=2><b>
$no_mail
</b></td></tr>
</table><br>";
exit;
}




?>

deveray
11-03-2007, 04:22 AM
Okay, next is the other page from the same website, in this case one that has the basic paginated results.




<head><title>MeetChristians.com - Search name results</title></head>

<?php
$icn_dir = "../icn";
$inc_dir ="./incl";
require "$inc_dir/first_values.inc.php";
require "$inc_dir/nav_bar.inc.php";
require "$inc_dir/ht_wt_opt.inc.php";
$this_script_url = "s_nlist.php";

$username = str_replace(" ", "", $username);

if ($lim < 1)
{
$query = "SELECT count(username) FROM main WHERE username LIKE '%$username%' AND gender='$g'";

$result = mysql_db_query($db, $query);

while ($row=mysql_fetch_row($result))
{
$total=$row[0];
}
}
else
{
$total =$lim;
}

$max_num_returns = 25;
$max_returns = $max_num_returns;
$returns = 0;
$first_returns = 0;
$prev_first_returns = 0;

if ($last > 0)
{
$first_returns = ($last + 1);
$max_returns = ($last + $max_num_returns);
$prev_first_returns = ($last - $max_num_returns);
}

#$rows = mysql_num_rows($result);
#print "rows $rows<BR>";

$query = "SELECT username, image1, image2, city, state, country, occupation, indoor_activity, outdoor_activity, first_visit, DATE_FORMAT(last_visit, '%m-%e-%y %H:%i'), age, height, weight, e_size, h_c, photo_date, expire, personality1, personality2, personality3, personality4
FROM main
WHERE username LIKE '%$username%'
AND gender='$g' AND age > '17' AND age < '99'
ORDER BY last_visit DESC LIMIT $max_returns";

$result = mysql_db_query($db, $query);
$rows = mysql_num_rows($result);



if ($rows == 0)
{
print "

<br>

<center><b><font face=tahoma,arial size=4><font color=mediumblue>Your search turned up $rows person(s).</font><br><br>

";
exit;
}


$previous_returns = "<b><a href=\"$this_script_url?tdy=$tdy&last=$prev_first_returns&g=$g&username=$username&lim=$total\"><< Previous $max_num_returns</a>";

$next_returns = "<b><a href=\"$this_script_url?&tdy=$tdy&last=$max_returns&g=$g&username=$username&lim=$total\">Next $max_num_returns >></a>";

if ($first_returns < 2)
{
$previous_returns = "";
}

if ($max_returns > $total)
{
$max_returns = $rows;
$next_returns = "";
}

print "



<TABLE cellSpacing=0 cellPadding=0 width=90% border=0>
<TBODY>
<TR>
<TD width=100%>
<table width=100% BGCOLOR=#C0FFFF borderColor=#666666 borderColorLight=#BBBBBB border=1 cellspacing=0 cellpadding=2>
<tr ALIGN=CENTER VALIGN=CENTER BGCOLOR=#0000DD>
<td><b><font face=arial color=white size=2>Name</td>
<td><b><font face=arial color=white size=2>Photo</td>
<td><b><font face=arial color=white size=2>Location / Occupation</td>
<td><b><font face=arial color=white size=2>Favorite Activities / Personality</td>
<td><b><font face=arial color=white size=2>Last Visit</td>
<td><b><font face=arial color=white size=2>Essay</td>
<td><b><font face=arial color=white size=2>Age/Ht./Wt.</td>
</tr>";

$now = date(Ymd);


while ($row=mysql_fetch_row($result))
{
$returns++;
$username =$row[0];
$image1 =$row[1];
$image2 =$row[2];
$city =$row[3];
$state =$row[4];
$country =$row[5];
$occupation =$row[6];
$indoor_activity = $row[7];
$outdoor_activity = $row[8];
$first_visit =$row[9];
$last_visit=$row[10];
$age =$row[11];
$height =$row[12];
$weight =$row[13];
$e_size =$row[14];
$h_c =$row[15];
$photo_date =$row[16];
$expire =$row[17];
$personality1 =$row[18];
$personality2 =$row[19];
$personality3 =$row[20];
$personality4 =$row[21];

$new_bgcolor = "";

if ($returns < $first_returns)
{
$continue = "y";
}
else
{

if ($returns > $max_returns)
{
table_footer();
print "
<table border=0 width=100%><tr>
<td>
<td align=left><font face=arial size=2>$previous_returns
</td>
<td align=right><font face=arial size=2>$next_returns
</td></tr></table>
";
exit;
}
find_first_values($height);

$first_visit = str_replace("-", "", $first_visit);
$first_visit = str_replace(":", "", $first_visit);
$first_visit = str_replace(" ", "", $first_visit);
$new = "";
if ($my_L_visit < $first_visit)
{
$new = "<img src=$icn_dir/new2.gif>";
}
$photo_date = str_replace("-", "", $photo_date);
$photo_date = str_replace(":", "", $photo_date);
$photo_date = str_replace(" ", "", $photo_date);
$n_pic = "";
if ($my_L_visit < $photo_date)
{
$n_pic = "<br><img src=$icn_dir/new2.gif>";
$new_bgcolor = "BGCOLOR=#FF0000";
}

print "

<tr ALIGN=CENTER VALIGN=CENTER>
<td><font face=arial size=-1><b>
<a href=focus.php?tdy=$tdy&name=$username>
$username</a>$new</td>
";

if ($image1 != "")

(removed some code here to make the page fit)

if ($h_m_c == "Y")
{
$city = "(cities hidden)";
}
elseif ($h_c == "Y")
{
$city = "(city hidden)";
}
print "
<td></form><font face=arial size=-1>$city &nbsp; $state &nbsp; $country<br><br> $occupation</td>
<td><font face=arial size=-1>$indoor_activity <br> $outdoor_activity<br><br>$personality1, $personality2, $personality3, $personality4</td>
<td><font face=arial size=-1>$last_visit</td>
<td><font face=arial size=-1>$e_size%</td>
<td><font face=arial size=-1>$age<br><br>
$height<br><br>
$weight</td>
</tr>
";
}
}

table_footer();

print "
<center><table border=0 width=100%><tr><td align=left width=25%><font face=arial size=2>$previous_returns</td>
<td align=right width=25%><font face=arial size=2>$next_returns</td></tr></table>
</center>";

page_footer();


exit;


?>

deveray
11-03-2007, 04:29 AM
PS:

I have already viewed or read about 7 tutorials on the topic. While some of them looked reasonable and fairly do-able for a complete novice who is able to read code okay while creating none of my own yet, figuring out how to adapt them for the site above is another step, which is of course missing from any of the tutes.