Jump to content

Listing previous 10 records


 Share

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
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
Link to comment
Share on other sites

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.

 Share

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