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


Taylor O'Reilly
Taylor O'Reilly
2,636 Points

Is there a reason to repeat the setting of $section?

Instead of setting the $section variable in each 'if' statement, wouldn't this code be more appropriate for the "dry" methodology?


if($_GET["cat"] == "books"){
  $pageTitle = "Books";
} else if ($_GET["cat"] == "movies"){
  $pageTitle = "Movies";
} else if ($_GET["cat"] == "music"){
  $pageTitle = "Music";
} else {
  $pageTitle = $pageTitle;
  $section = $pageTitle; // if there is a $pageTitle set this will set $section
} else {
  $section = null; // if $pageTitle is not set $section goes to null

are there any draw backs to doing it this way?

Sounds good, but hard to say for sure since we can't see what you are replacing. It always helps if you give a link to the video.