Jump to content

Recommended Posts

I want to list the previous (minus) 10 records.
classic asp example:  <% do while not rs.eof and i< 7 %>
how to do with php pdo?

My code is this:
<?php
$sqlq=$connectx->prepare("SELECT * FROM lovetree ");
$sqlq->execute();
while($rs = $sqlq->fetch()) {

echo $rs['tree'];

}
?>

Thanks...

Link to comment
https://forums.phpfreaks.com/topic/312381-listing-previous-10-records/
Share on other sites

Then add DESC to the LIMIT clause:

$sqlq=$connectx->prepare("SELECT * FROM lovetree DESC LIMIT 10");

That sorts in descending order which means the rows are upside down so the limit 10 results in the last 10 rows. Note the first row returned was the last row in the table. You may want to resort the resulting array to turn it right side up, if that matters.

Edited by gw1500se
1 hour ago, DisplayError said:

As if there were no first 10 records - next 10 records will be print to the screen.

How can that situation even be possible?

@DisplayError If you tell us what you are trying to do in a clear, logical manner then we can probably help. Otherwise you're on your own.

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.