Jump to content

Recommended Posts

hello everyone. Need a little help on my code, im not far but still not be able to navigate trough recorset bar navigation....

the script who display images from a database...

 

<?php require_once('Connections/dblink.php'); ?>
<html>
<head>
<title>Galery</title>
</head>
<table>
<?php
$current_page = $_SERVER["PHP_SELF"];
$ImageDir = "images/";
$ImageThumb = $ImageDir . "thumbs/";
$limit=5; 
mysql_select_db($database_ligacaoDados, $ligacaoDados);
$numresults = mysql_query("SELECT * FROM images");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
    $offset=0;
}
$getpic=mysql_query("select * from images LIMIT $offset, $limit");
while ($rows = mysql_fetch_array($getpic)) {
  extract($rows);
  echo "<tr>\n";
  echo "<td><a href=\page.php?id=$image_id .\">";
  echo "<img src=\"images/thumbs/". $image_id . ".jpg\" border=\"0\">";
  echo "</a></td>\n";
  echo "<td>" . $image_caption . "</td>\n";
  echo "<td>" . $image_description . "</td>\n";
  echo "<td>" . $image_date . "</td>\n";
  echo "</tr>\n";
}
// next we need to do the links to other results

if ($offset>1) { // bypass PREV link if offset is 0
    $prevoffset=$offset-5;
    print "<a href=\"$current_page?offset=$prevoffset\">PREV</a>   \n";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
    // has remainder so add one page
    $pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
    $newoffset=$limit*($i-1);
    print "<a href=\"$current_page?offset=$newoffset\">$i</a>   \n";
}

// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
    // not last page so give NEXT link
    $newoffset=$offset+$limit;
    print "<a href=\"$current_page?offset=$newoffset\">NEXT</a><p>\n";
}
?>
</table>
</body>
</html>

 

everything works exept that i can't navigate trough the recorset (prev 1234 next)....did i miss something on my tutorial?

could someone kindly give a kick on my code?

in advance thank you

best regards

Sam

Link to comment
https://forums.phpfreaks.com/topic/95582-question-about-pagination/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.