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 trial

PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Working with _GET Variables

Working with _GET Variables

I have a general question nothing regarding a error, for the example below, when we put the variable at the end of the url, does this create an actual different page file that we can edit on the server? For example

<ul class="nav">
            <li class="books"><a href="catalog.php?cat=books">Books</a></li>
            <li class="books"><a href="catalog.php?cat=movies">Movies</a></li>
  </ul>

the 2 url pages above, I know catalog.php page file actually exist, but since its the same page and were only adding a variable at the end of the url, if I want actual content to be different for each page is there a file that you would edit to change the actual content? like would it create an additional file will there be 2 different php files in the server? Or would it just be one which is catalog.php only in the server?

2 Answers

In this case you could create two individual files and use an include. And then use a switch case or if / else conditional to check the $_GET variable and load the appropriate page. Or you can include all the content inside catalog.php - it's really up to you how you deal with it.

With the example you've posted, I think the course uses the $_GET variable to pass to a function that returns either all of the books or all of the movies. So the page content is actually all done on catalog.php and it's identical, the only difference is that it's pulling either all of the books or all of the movies from the database to display them.

oh that makes sense now what you were saying about within the if statement when checking with the $_GET variable also have it load the appropriate page in the same statement. Thanks I appreciate it