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 trial

PHP

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.

Jeff

<?php

$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

?>