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 trialJeff Styles
2,784 PointsRandy refreshed shirt.php and url id=102 seemed to be randomly generated? Where was id=102 specified?
While randy was demonstrating echoing $product_id and var_dump($product) on shirt.php, how did page id=102 come into play after refresh? He only seemed to specify $_get[id], not 102. When I try this by refreshing shirt.php i receive a null error. However, If I open shirts.php in my browser, and select shirt 102, the product id is echoed and the var_dump is run What am i missing? Thanks!
Luca Argenziano
16,416 PointsHi Jeff, maybe I can help you. id=102 is not randomly generated; it refers to the index of your products array. If you look inside the square brackets in the products.php file you will see that each product has an index like 101, 102 etc. Maybe you're missing this: in the foreach method, in the shirts.php file, you need to pass the product id in this way:
<?php foreach($products as $product_id => $product) { ... } ?>
Then, for viewing it in the url, you need to modify the href to include it. Here is the line of code (now we are inside the foreach):
echo '<a href="shirt.php?id=' . $product_id .'">';
Now, as you can see, we've passed the variable that contains the specific id of each shirt to the url. This have to work properly ;)
I hope I helped you.
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsJust for future reference whenever asking a question you will have a much high chance of getting an answer if you post your code along with your question.