Jump to content

"Next 25 entries" and "Previous 25 entries" code


ArjanR

Recommended Posts

Hi,
I'm new here and also a newbee in the world of php. I tried looking through the forum's archive if I could find topics dealing with my problem, but I couldn't find one (although I know they exist cos it's quite a basic question I think.)

Anyway, what I am looking for is a way to spread out entries from a database over multiple pages, and being able to switch back and forth between those pages via "Previous 25 entries" and "Next 25 entries" at the bottom of the page.

The page it is for uses the following code to retrieve the last 25 entries (pictures) out the database:

(The actual website page is visible here: [a href=\"http://www.plasticdaisy.net/last25.php)\" target=\"_blank\"]http://www.plasticdaisy.net/last25.php)[/a]

<?
if (! $archive) {
$res = mysql_query("SELECT COUNT(*) FROM photo", $con);
$row = mysql_fetch_array($res);
$total = $row[0];
$nr = $total - 5;
$res = mysql_query("SELECT * FROM photo ORDER BY msgid DESC LIMIT $nr, $total", $con);
$res = mysql_query("SELECT * FROM photo ORDER BY msgid DESC LIMIT 25", $con);
} else {
$res = mysql_query("SELECT * FROM photo ORDER BY msgid DESC", $con);
}

while ($row = mysql_fetch_array($res)) {
$msgid = $row["msgid"];
echo "<br>";
echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
echo "<tr><td colspan=4 align=center>";
echo "<b>" . strip_tags($row["title"]) . "</b>" . "<br>";
echo "<br><a href=\"index.php?msgid=$msgid\"><img border=0 src=/images/digicam/" . strip_tags($row["url"]) . " class=red alt='Click to read comments'>" . "</a>";
echo "</td></tr>";
echo "<tr><td width=45></td><td>";

$msgdate = $row["msgdate"];
list ($year, $month, $day, $hours, $minutes, $seconds ) = split ('[-: ]', $msgdate);
echo "$day-$month-$year";
echo "</td><td align=right> ";
$res2 = mysql_query("SELECT count(*) FROM photoremarks WHERE msgid=$msgid", $con);
$row2 = mysql_fetch_array($res2);
echo "<a href=\"index.php?msgid=$msgid\">comments: " . $row2[0] . "</a>" . "<br>";
echo "  </td><td width=45></td></tr>" . "<br>";

echo "</table>";
echo "<br><img src=img/onder.gif>";
echo "<br>";
}
mysql_free_result($res);
?>


Does somebody have a suggestion how I can reuse this page as a basis, so just by giving the links for "Next 25" and "Previous 25" some extra parameter with which a query on the database is defined.

Hope I explained it clearly! Any help is welcome! Thanks in advance.

Arjan
Link to comment
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.