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 trialSimon Strömberg
1,423 PointsCant get the concatenation to work
<?php include("inc/products.php"); ?><?php
$pageTitle = "Unique t-shirts";
$section = "shirts";
include('inc/header.php'); ?>
<div class="section shirts page">
<div class="wrapper">
<h1>Mikes’s Full Catalog 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'); ?>
6 Answers
Maciej Sularz
15,088 PointsThen you must have an error elsewhere in the code, can you please post the contents of products.php
, header.php
and footer.php
files as well? I will quickly check them for you :)
It must be a typo :) also place this on the very top of your code:
<?php
// Enables error reporting
error_reporting(E_ALL);
ini_set("display_errors", 1);
include("inc/products.php");
// Rest of yout code goes here...
?>
It should show php errors instead of a blank page :)
Simon Strömberg
1,423 PointsThank you, that error code showed the issue. Was issue in products.php page, Now it works =)
Maciej Sularz
15,088 PointsGlad I could help, it's good practice to have error reporting ON while in development - saves you a lot of time :)
Good luck for the fututre!
Kind regards, Maciej Sularz
Simon Strömberg
1,423 Pointswhat is the issue? I have set up the products file and shirt file. But when i click on a image i only come to this link: http://port-80-o8ngbeg2s8.treehouse-app.com/shirts.php
Sean T. Unwin
28,690 PointsOn line 15 :
echo'<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'
you forgot the semi-colon at the end of the line. That's all. :)
Simon Strömberg
1,423 Points<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>
Still doesnt work
Sean T. Unwin
28,690 PointsHmm. I just tested against my Shirts4Mike project and it worked after I added the semi-colon.
Sean T. Unwin
28,690 PointsWhat error are you getting or what shows up on the page?
Maciej Sularz
15,088 PointsYou are missing a semicolon at the end of the line after <img> tag in your <ul> element.
Let me know if that solves the problem :)
<?php
echo'<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'
?>
Simon Strömberg
1,423 PointsIt didnt solve it
Simon Strömberg
1,423 PointsIt comes up a white blank page on this url: http://port-80-o8ngbeg2s8.treehouse-app.com/shirts.php
Maciej Sularz
15,088 PointsTry this code, is the $products
defined in the header?
<ul class="products">
<?php
$products = array(
array(
'img' => 'http://placehold.it/150x150',
'name' => 'Product 1 Name'),
array(
'img' => 'http://placehold.it/150x150',
'name' => 'Product 1 Name'),
array(
'img' => 'http://placehold.it/150x150',
'name' => 'Product 1 Name')
);
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>
Simon Strömberg
1,423 PointsNo, still same.
Sean T. Unwin
28,690 PointsNo, still same.
Do any other pages load correctly from the project's workspace, like the index?
Sean T. Unwin
28,690 PointsSean T. Unwin
28,690 PointsI formatted your code for readabiliity.
Please see this thread for posting code to the forum. :)