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.

PHP Using PHP with MySQL Using Relationship Tables in MySQL Fetching in a While Loop

Moritlha Madisha
Moritlha Madisha
5,014 Points

Little confused

Hi all!

I'm a little confused with this statement in this lesson. Please look at my question in the question mark after reading the code. Randy Hoyt

while( $row = $results->fetch(PDO::FETCH_ASSOC)) { $product["sizes"][] = $row["size"]; } //why are we does $row["size"] have size instead of "sizes" like the // $product["sizes"] variable?

2 Answers

Colin Marshall
Colin Marshall
32,860 Points

Each row only has one size in it. The loop takes all of the sizes available for that shirt and loads them into $product array with the rest of the shirt's details. It loads the array into the "sizes" key for the $product array.

Moritlha Madisha
Moritlha Madisha
5,014 Points

Thanks Colin. I eventually understood the concept through the exercises. The "size" refers to the column in the table and "sizes" refers to "sizes" key in the product array.