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 trialCassandra James
7,561 PointsWorking with Functions
Here is the code in my products.php file
<?php //line 4 use concatenation to build list item as a piece of text, create output with a blank value function get_list_view_html($product_id, $product) {
$output = $output . "<li>";
$output = $output . '<a href="shirt.php?id=' . $product_id . '">';
$output = $output . '<img src="'. $product["img"] .'" alt="'. $product["name"] .'">';
$output = $output . "<p>View Details</p>";
$output = $output . "</a>";
$output = $output . "</li>";
return $output;
}
$products = array();
$products[101] = array(
"name" => "Logo Shirt, Red",
"img" => "img/shirts/shirt-101.jpg",
"price" => 18,
"paypal" => "9P7DLECFD4LKE",
"sizes" => array("Small", "Medium","large", "X-Large")
);
$products[102] = array(
"name" => "Mike the Frog Shirt, Black",
"img" => "img/shirts/shirt-102.jpg",
"price" => 20,
"paypal" => "SXKPTHN2EES3J",
"sizes" => array("Small", "Medium","large", "X-Large")
);
$products[103] = array(
"name" => "Mike the Frog Shirt, Blue",
"img" => "img/shirts/shirt-103.jpg",
"price" => 20,
"sizes" => array("Small", "Medium","large", "X-Large")
);
$products[104] = array(
"name" => "Logo Shirt, Green",
"img" => "img/shirts/shirt-104.jpg",
"price" => 18,
"sizes" => array("Small", "Medium","large", "X-Large")
);
$products[105] = array(
"name" => "Mike the Frog Shirt, Yellow",
"img" => "img/shirts/shirt-105.jpg",
"price" => 25,
);
$products[106] = array(
"name" => "Logo Shirt, Gray",
"img" => "img/shirts/shirt-106.jpg",
"price" => 20
);
$products[107] = array(
"name" => "Logo Shirt, Turquoise",
"img" => "img/shirts/shirt-107.jpg",
"price" => 20
);
$products[108] = array(
"name" => "Logo Shirt, Orange",
"img" => "img/shirts/shirt-108.jpg",
"price" => 25
);
?>
When I click on http://localhost/shirts.php I get the following error: Notice: Undefined variable: output in C:\xampp\htdocs\inc\products.php on line 5
I do not know how to correct this error; I do not understand the purpose of the code : [$output = $output . "<li>";]
2 Answers
Kang-Kyu Lee
52,045 Pointsmaybe because at beginning
$output = "";
missing?
Cassandra James
7,561 PointsYes it is missing but it is based on the instruction in the video unfortunately I do not know what to input. :)