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 Integrating PHP with Databases Limiting Records in SQL Calculations and Links

Geraldo Hernandez
Geraldo Hernandez
7,515 Points

How does the ampersand (&) allow us to pass the page number?

From the video, when Alena is limiting the results in redirect, she writes the following code:

if(isset($_GET["pg"])){
    $current_page = filter_input(INPUT_GET, "pg", FILTER_SANITIZE_NUMBER_INT);
}
if(empty($current_page)){
    $current_page = 1;
}

$total_items = get_catalog_count($section);

$total_page = ceil($total_items / $items_per_page);     // round upward

// redirect too-large page numbers to the last page
if($current_page > $total_pages){
    header("location:catalog.php?pg="
        . $limit_results
        . "pg=" . $total_pages);
}
// redirect too-small page numbers to the first page
if($current_page < 1){
    header("location:catalog.php?pg=1");
}

// limit results
$limit_results = '';
if(!empty($section)){
    // ampersand (&) at end will allow us to pass page number
    $limit_results = "cat=" . $section . "&";
}

I'm confused as to how she uses the ampersand to grab the current page number. The part in question is at the very last few lines of code.