0

I'm just wondering how I could fetch data using a while loop at row 5 in my SQL table and end it at row 8.

Here is an example of my current code:

while($row = $results->fetch(PDO::FETCH_ASSOC))
                        {
                        echo '
                        <li>Mileage: '.number_format($row["Mileage"]).'</li>
                        <li>Engine size: '.$row["EngineSize"].'cc</li>
                        ';} ?>

So as you can see I'd like to make it so the while loop only loops from row 5 to row 8 so I'd be left with 4 li's with the unique data in those columns. As it stands it is currently looping every row in the SQL table which is what I don't want.

Any code examples would be great as I am really stuck on this at the moment. Thanks.

1
  • The answer from Sujit is most likely what you want but an answer to the literal question (start looping an array at a specific index): stackoverflow.com/questions/795625/… Commented Sep 15, 2014 at 21:25

1 Answer 1

1

MySQL developers and SQL designers must have actually been able to predict this question years back. :)

LIMIT clause comes to your rescue

http://www.mysqltutorial.org/mysql-limit.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.