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 trialJames Ma
19,063 PointsGetting links to work?
On this project, I was wondering how the "view details" link is able to work. From my understanding it is a <p> element, so how is the functionality to link "view details" to the actual details is able to work? It is not explained in the video?
4 Answers
Lindsay Sauer
12,029 PointsAlright, I think I know what you're asking, but let me know if I don't answer your question fully.
The anchor element <a> defines a hyperlink to a location, either on the same page or to a different page. The act of navigating on click is handled by the browser.
The get_item_html function returns, in part, an anchor element with a link to the page details.php. As well, this link includes a GET parameter id which tells the details.php page what item's details to display. The GET parameter id is set to the value of a parameter passed to the get_item_html function, $id:
<a href='details.php?id=". $id ."'>
Thereby creating a link like:
http://port-80-bfl8tlr2r9.treehouse-app.com/details.php?id=103
Lindsay Sauer
12,029 PointsHi James,
I'm not seeing a "View Details" link on the video, does this appear elsewhere in the lesson?
James Ma
19,063 Pointsno, its right under the books/movies/music. its generated in the get_item_html function. I just want to know how you got it to link to the actual details section.
Lindsey Somerset
10,592 Points<a href="details.php?id=301">
<img src="img/media/beethoven.jpg" alt="Beethoven: Complete Symphonies">
<p>View Details</p>
</a>
The paragraph element links to the details section because it is nested in the anchor tag (included before the closing tag). If "View Details" was not in a paragraph tag, it would still be a clickable link that leads to the details section because it's contained within the anchor or <a> tag.
Hope this helps!