Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


question about PHP ordering latest products

I don't understand how concatenating $list_view_html at the end instead of before get_list_view_html($product_id, $product) reverses the order of the products? Can you help me understand why this works?

2 Answers

If i understand correctly, you can change the order of the results by doing for example "ORDER BY date DESC"

Hi Eric,

I believe it works like this. First, to simplify things we are going to call $list_view_html $lvh and get_list_view_html($product_id,$product) glvh(). If I'm wrong I hope someone corrects me.



$lvh = "";

$lvh = $lvh . glvh(101);
// $lvh now eguals 101

$lvh = $lvh . glvh(102);
// $lvh now equals 101, 102

$lvh = $lvh . glvh(103);
// $lvh now equals 101, 102, 103

$lvh = $lvh . glvh(104);
// $lvh now equals 101, 102, 103, 104

// Now let's switch things around

$lvh = glvh(101) . $lvh;
// $lvh now eguals 101

$lvh = glvh(102) . $lvh;
// $lvh now eguals 102, 101

$lvh = glvh(103) . $lvh;
// $lvh now eguals 103, 102, 101

$lvh = glvh(104) . $lvh;
// $lvh now eguals 104, 103, 102, 101