Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialYousuf Tafhim
8,402 PointsWhy apply reverse after we have taken the data from the database in descending order?
In the video we are first writing an SQL Query which return 4 rows in descending order so the records are already coming as 132, 131, 130, 129. But then we are again reversing the order with array_reverse().won't this will make it back to 129, 130, 131, 132?
2 Answers
haunguyen
14,985 PointsChanging it back to 129, 130, 131, 132 is to match the intention mentioned in the comment section of the code.
We used DESC to fetch the last 4 shirts, and the order of the fetch is 132, 131, 130, 129.
But in the front end, we want to display the most recent shirts by 129, 130, 131, 132.
Randy wanted to keep this order to maintain display out consistency to keep you having to keep track of which output order is from which block of code.
We can also use ASC and use additional maths to fetch the last four items and not having to use array_reverse, but this is easier.
Aaron Munoz
11,177 PointsMake sure to post the answer in the answer box so people know this question was solved. Thanks Huanguyen
Yousuf Tafhim
8,402 PointsYousuf Tafhim
8,402 PointsThanks huanguyen, I was initially thinking that the last product will be the first product on the main page