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,858 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.