PDA

View Full Version : Want to display the current page I am looking at in a recordset


woofy
12-26-2010, 08:56 PM
I want to display the current page value I am looking at in my recordset, for example I want to see that I am looking at page 3 of 10...

Right now the problem I am running into is when I try to display that value it gives me them in reverse order, for example page 1 of 10 reads page 10 of 10, where page 10 would say page 1 of 10... I need the exact opposite. The display recordset function I am using is dreamweavers display ending record number which looks like this...


<?php echo min($startRow_rsPAGEID + $maxRows_rsPAGEID, $totalRows_rsPAGEID) ?>


Is there a way and how can I rewrite that line to work in the exact opposite manner?

jmichae3
12-28-2010, 04:25 AM
you need to provide your source code, I can't see into your computer.


to do what you are asking, you need to modify your database query using LIMIT $start,$size
and I used the following working navigation code:


<?php
function navcontrols($baseurl, $start, $recordsPerLink,$rowcount) {
//show navigation controls
$maxNumLinks=12;
if ($start < 0) {$start = 0;}
if ($start >= $rowcount) {$start = $rowcount-1;}
$currentPageNum=1+intval($start/$recordsPerLink);

echo "<div style='font-size:small;text-align:center;'>";
if ($start!=0) {
echo "<a href=\"${baseurl}index=0\">|&lt;&lt;Start</a> ";
}
$n2=$start-$maxNumLinks*$recordsPerLink;
if ($n2>=0) {
echo "<a href=\"${baseurl}index=${n2}\">&lt;&lt;Prev&nbsp;${maxNumLinks}&nbsp;pgs</a> ";
}

//if $start within last $recordsPerLink pages, display previous $recordsPerLink pages
//else display pages starting with $start for $recoredsPerLink pages
if ($start >= $rowcount - $recordsPerLink*$maxNumLinks && $rowcount - $recordsPerLink*$maxNumLinks >= 0) {
for ($x=$rowcount - $recordsPerLink*$maxNumLinks;
$x < min($start + $recordsPerLink*$maxNumLinks, $rowcount);
$x+= $recordsPerLink) {
//make guestbook navigation link
if ($start+$size<$rowcount) {
$pagenum=1+intval($x/$recordsPerLink);
if ($pagenum == $currentPageNum) {
echo "[$pagenum] ";
} else {
echo "<a href=\"${baseurl}index=$x\">[$pagenum]</a> ";
}
}
}
} else {
for ($x=$start; $x < min($start + $recordsPerLink*$maxNumLinks, $gbcount); $x+= $recordsPerLink) {
//make guestbook navigation link
if ($start+$size<$rowcount) {
$pagenum=1+intval($x/$recordsPerLink);
if ($pagenum == $currentPageNum) {
echo "[$pagenum] ";
} else {
echo "<a href=\"${baseurl}index=$x\">[$pagenum]</a> ";
}
}
}
}
$n2=$start+$maxNumLinks*$recordsPerLink;
if ($n2<$gbcount) {
echo "<a href=\"${baseurl}index=${n2}\">Next&nbsp;${maxNumLinks}&nbsp;pgs&gt;&gt;</a> ";
}

/*
if $start is between $0 and intval(($rowcount-1)/$recordsPerLink)*$recordsPerLink inclusive, do link
$n=intval(($gbcount-1)/$recordsPerLink)*$recordsPerLink;
the maximum of
*/
$pagenum=1+intval($start/$recordsPerLink);
$n1=min($rowcount-$recordsPerLink, $start);
$n2=min($rowcount-($gbcount-$start), $start);
$n=intval(($rowcount-1)/$recordsPerLink)*$recordsPerLink;
if ($start!=0 && ($start >= 0 && $start <= intval(($gbcount-1)/$recordsPerLink)*$recordsPerLink)) {
echo "<a href=\"${baseurl}index=$n\">End&gt;&gt;|</a> ";
}
echo "<br><br>";
echo "</div>";
}





$start=0;
$size=getconfigval('guestbook-entries-per-page'); //number of entries per page
if (isset($_GET['index']) && intval($_GET['index'])>0) {
$start=intval($_GET['index']);
}


$gbcount=guestbooktotalrecordcount(1);
echo "<p><span class='gbcount'>&nbsp;" . /*sprintf("%05d",*/$gbcount/*)*/ . "&nbsp;</span> guestbook entries</p>";
navcontrols("guestbook.php?", $start, $size,$gbcount);

$q=0;
if ('on'==$approvalsystem) {
$q = mysql_query("SELECT * FROM gbook,approval_values
WHERE gbook.approvalid=approval_values.id AND approval_values.valname='approved'
ORDER BY dt DESC
LIMIT $start,$size", $link);

} else {
$q = mysql_query("SELECT *
FROM gbook
ORDER BY dt DESC
LIMIT $start,$size", $link);
}
if ($q && mysql_num_rows($q)>0) {
while ($row = mysql_fetch_array($q)) {
$dta = explode(' ', $row['dt']);
$dt=explode('-', $dta[0]);
$tm=$dta[1];
echo "<table width='100%' border='1' cellspacing='0' bordercolor='Navy'><tr><td>";
echo "<table width='100%' border='0'><tr><td>$dt[1]/$dt[2]/$dt[0] $tm</td><td width='100%'>";
if ('' == stripslashes($row['email'])) {
echo htmlspecialchars(stripslashes($row['nm']));
} else {
echo '<a href="mailto:' . stripslashes($row['email']). '">'.htmlspecialchars(stripslashes($row['nm'])).'</a>';
}
if (isset($row['hailfrom']) && ''!=$row['hailfrom']) {
echo " from " . htmlspecialchars(stripslashes($row['hailfrom']));
}
if (isset($row['url']) && ''!=$row['url']) {
echo " [<a href=\"" . htmlspecialchars(stripslashes($row['url'])) . "\">Web&nbsp;Site</a>]";
}
echo "</td></tr>";
echo "<tr><td></td><td align='left' width='100%'>"./*html_entity_decode(*/stripslashes($row['tx'])/*)*/."</td></tr>";
echo "</table>";

echo "</td></tr></table><br>";
}

navcontrols("guestbook.php?", $start, $size,$gbcount);

} else {
echo "You are the first one!";
}
mysql_free_result($q);
?>

this was from a guestbook of mine. you can see the entire GPL'd source code at http://jesusnjim.com/code/php/guestbook.html
I suggest you have a look at that code, and rename 1 or two variables for your needs, for instance $gbcount and maybe $size. also look at nav.php and guestbook.php, those are where you are going to find the interesting code to your problem. it's where the navigation is.