mivec
04-16-2004, 04:23 PM
hi all,
ok i don't know if any of u can help me in this.
scenario:
i am trying to build a page where will only display 6 records(images). so u may ask what if it's more than six? yes..this is what i am trying to do. this page only displays 6 images at one time eventhough it is 100images in the DB. so...there will be page numbers like this forum has <<1 2 3 4...>> and each of these can only display 6 images. so if there are 12 images there should only be 2 pages..<<1 2>>. if there are only 6 images then it would be <<1>>. understand what i am trying to say here?:). it's sopmething like a page browser where u can go to any number of page u like and it will display the records there.
actually..i have the code here.i have done partially of it but it doesn't raelly work like how it is suppose to be. it can go to the page u want but it won't display it out and when u go to the next page or previous the records just don't display. here is the code
$sql = "SELECT * FROM tblgallery WHERE username = '" . $_GET["username"] . "'";
$rs = mysql_query($sql);
$nRows = mysql_num_rows($rs);
/* Set the default records to be shown per page as 5 */
$pageSize = 3;
/* Page is not set then set it to page 1 */
if(!isset($_GET["page"]))
$page = 1;
else
$page = $_GET["page"];
$startPos = $page * $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
$sql .= ' LIMIT ' . $startPos . ', ' . $pageSize; //now break into paged sections
$rs = mysql_query($sql) or die('Error: ' . mysql_error());
echo('<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
echo(' <tr><td align=right><span class="nav">');
if ($page != 1) {
$prev = $page - 1;
echo '<span class="nav"><a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'"><<</a>';
}
else
echo ("<span class=\"nav\"><<");
$totalPage = $nRows / $pageSize;
for($i = 1; $i <= $totalPage; $i++) {
/* inactive page, don't add linking */
if ($i == $page){ echo ' ' . $i;}
/* page active, add linking */
else {echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>';}
}
if (($nRows % $pageSize) != 0) {
/* inactive page number */
if ($i == $page){ echo ' ' . $i; }
/* active page, linked */
else {echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>'; }
}
if( ($nRows - ($pageSize * $page)) > 0) {
$next = $page + 1;
echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $next . '">>></a></span>';
}
else{
echo " >></span>";
echo("</td>");
echo("</tr>");
echo("</table>");
echo('<table width="100%" border="0" cellspacing="1" cellpadding="4">');
while ($row = mysql_fetch_object($rs)) {
echo("<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
<td align=center border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>");
}//close while
the username comes from this which i have posted before:
echo("<tr bgcolor=\"#FEDCED\">
<td width=\"12%\"> </td>
<td width=\"6%\"> </td>
<td width=\"82%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#104071\"><a href=\"photoUpload.php?username=".$_POST['txtUserID']."&mode=list\">-Upload New Photo</a></font></td>
</tr>");
i have already corrected the syntax so..it's correct now. but now the focus is on the page browsing. pls help for the last time.....i am going nuts already.
ok i don't know if any of u can help me in this.
scenario:
i am trying to build a page where will only display 6 records(images). so u may ask what if it's more than six? yes..this is what i am trying to do. this page only displays 6 images at one time eventhough it is 100images in the DB. so...there will be page numbers like this forum has <<1 2 3 4...>> and each of these can only display 6 images. so if there are 12 images there should only be 2 pages..<<1 2>>. if there are only 6 images then it would be <<1>>. understand what i am trying to say here?:). it's sopmething like a page browser where u can go to any number of page u like and it will display the records there.
actually..i have the code here.i have done partially of it but it doesn't raelly work like how it is suppose to be. it can go to the page u want but it won't display it out and when u go to the next page or previous the records just don't display. here is the code
$sql = "SELECT * FROM tblgallery WHERE username = '" . $_GET["username"] . "'";
$rs = mysql_query($sql);
$nRows = mysql_num_rows($rs);
/* Set the default records to be shown per page as 5 */
$pageSize = 3;
/* Page is not set then set it to page 1 */
if(!isset($_GET["page"]))
$page = 1;
else
$page = $_GET["page"];
$startPos = $page * $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
$sql .= ' LIMIT ' . $startPos . ', ' . $pageSize; //now break into paged sections
$rs = mysql_query($sql) or die('Error: ' . mysql_error());
echo('<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
echo(' <tr><td align=right><span class="nav">');
if ($page != 1) {
$prev = $page - 1;
echo '<span class="nav"><a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'"><<</a>';
}
else
echo ("<span class=\"nav\"><<");
$totalPage = $nRows / $pageSize;
for($i = 1; $i <= $totalPage; $i++) {
/* inactive page, don't add linking */
if ($i == $page){ echo ' ' . $i;}
/* page active, add linking */
else {echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>';}
}
if (($nRows % $pageSize) != 0) {
/* inactive page number */
if ($i == $page){ echo ' ' . $i; }
/* active page, linked */
else {echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $i . '">' . $i . '</a>'; }
}
if( ($nRows - ($pageSize * $page)) > 0) {
$next = $page + 1;
echo ' <a href="' . $_SERVER['PHP_SELF'] . '?mode=list&page=' . $next . '">>></a></span>';
}
else{
echo " >></span>";
echo("</td>");
echo("</tr>");
echo("</table>");
echo('<table width="100%" border="0" cellspacing="1" cellpadding="4">');
while ($row = mysql_fetch_object($rs)) {
echo("<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
<td align=center border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>");
}//close while
the username comes from this which i have posted before:
echo("<tr bgcolor=\"#FEDCED\">
<td width=\"12%\"> </td>
<td width=\"6%\"> </td>
<td width=\"82%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#104071\"><a href=\"photoUpload.php?username=".$_POST['txtUserID']."&mode=list\">-Upload New Photo</a></font></td>
</tr>");
i have already corrected the syntax so..it's correct now. but now the focus is on the page browsing. pls help for the last time.....i am going nuts already.