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 trialjarrod Reeves
6,357 PointsThe array number is not changing when I click on each shirt
Hi This is my shirts.php code.
<?php include("inc/products.php"); ?><?php
$pageTitle = "Mike's Full Catelog of Shirts";
$section = "shirts";
include('inc/header.php'); ?>
<div class="section shirts page">
<div class="wrapper">
<h1>Mikes Full catelog of Shirts </h1>
<ul class="products">
<?php foreach($products as $product_id => $product) {
echo "<li>";
echo '<a href="shirt.php?id=' . $product_id . '">';
echo '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
echo "<p>View Details</p>";
echo "</a>";
echo "</li>";
}
?>
</ul>
</div>
</div>
<?php include('inc/footer.php'); ?>
Whenever I click on each shirt, only 101 is displayed and not 102, 103 etc.
I have looked over the code dozens of times and cannot find the problem.
1 Answer
Christian Andersson
8,712 PointsYour comparison operator on line 13 is incorrect. It's the other way around: >=
for greater-or-equal-to and <=
for less-or-equal-to. The equal-sign always trails the bracket.
Also, as a side-note: I don't think it's a good practice to use spaces in class names (such as your "section shirts page"). I always avoid spaces because, even if it works most of the time, it can cause big headaches when it doesn't. Using spaces (and some other special characters) in any programming language is a bad habit. Use dashes or underscores instead.
Good luck.
jarrod Reeves
6,357 Pointsjarrod Reeves
6,357 PointsThank you. It worked!
Even though I am no expert, I do agree with you on the class names. I am just following the way Randy is doing it in the video.
Adam Tatusko
16,589 PointsAdam Tatusko
16,589 PointsThat's not a comparison operator, that is an associative array assignment operator for
key => value
pairs.
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsYes, you are right Adam. I noticed my error as well. In the rush, I was thinking of a regular
for
loop. Oh well...Adam Tatusko
16,589 PointsAdam Tatusko
16,589 Pointsc'est la vie :-)