Or if you wanted to do it all in PHP, without using LIMIT, you could do
something like this.
I'm not exactly sure how your database is set up, so I just used this
made this dummy table as the one I will use in this example:
create table topics(id int(8) not null auto_increment, topic
varchar(30), author varchar(20), body text, primary key(id));
Ok, so then I just inserted some random data into to test with.
Here is some PHP code:
<?php
$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table", $link);
$num_rows = mysql_num_rows($result);
$all = array();
while ($topic = mysql_fetch_assoc($result)) {
$all[] = $topic;
}
if (isset($_GET['start'])) {
$start = $_GET['start'];
} else {
$start = 0;
}
for($i = $start; $i < $start + 15; $i++) {
echo "Topic ID: ". $all[$i]['id'] ."<br />";
echo "Topic Title: ". $all[$i]['topic'] ."<br />";
echo "Topic Author: ". $all[$i]['author'] ."<br />";
echo "Topic Body: ". $all[$i]['body'] ."<br />";
echo "<hr>";
if ($i == $start + 14) {
echo "<p><a href=\"pages.php?start=".($i+1)."\">Next
Page</a></p>";
}
}
mysql_free_result($result);
mysql_close($link);
?>
That will do simple paging, and works seems to work fine.
On Tue, 2004-09-28 at 22:05, Nick Patsaros wrote:
> I'm trying to build a bulletin style system right now. I have topics
> and replies to each topic. If a topic gets more than 15 replies I
> want them to start carrying over onto page 2 and then 3 and so on with
> 15 replies per page.
>
> The key that I'm missing I guess is, how do I keep track of the last
> accessed row in the database? So if I run a LIMIT 15 I can go back
> and pick up where I left on previously? Using the primary key isn't
> going to help because if posts get deleted I would have less than 15
> per page.
>
> Maybe I'm totally lost on this though, if someone could give me a bit
> of help on the most efficient way to accomplish this.
>
> --Nick
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php