Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Limiting Records in SQL Calculations and Links

Geraldo Hernandez
Geraldo Hernandez
7,513 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.