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

Amit Kumar
Amit Kumar
1,063 Points

I am not getting why & is used in this code and can you tell me process of else block its confusing..

$pagination = "<div class=\"pagination\">"; $pagination .= "Pages: ";
for ($i = 1;$i <= $total_pages;$i++) { if ($i == $current_page) { $pagination .= " <span>$i</span>"; } else { $pagination .= " <a href='catalog.php?"; if (!empty($search)) { $pagination .= "s=".urlencode(htmlspecialchars($search))."&"; } else if (!empty($section)) { $pagination .= "cat=".$section."&"; } $pagination .= "pg=$i'>$i</a>"; } } $pagination .= "</div>";

1 Answer

$pagination = "<div class=\"pagination\">";

$pagination .= "Pages: ";

for ($i = 1; $i <= $total_pages; $i++) {

  if ($i == $current_page) { 

              $pagination .= " <span>$i</span>";   // here maybe a mistake, try it: $pagination .= " <span>".$i."</span>";

   } else { 

               $pagination .= " <a href=/'catalog.php?";        // i just put escape char before '

               if (!empty($search)) {

                             $pagination .= "s=".urlencode(htmlspecialchars($search))."&"; 

                } else if (!empty($section)) {  

                              $pagination .= "cat=".$section."&";

                } 

                $pagination .= "pg=$i'>$i</a>";    // here maybe a mistake, try it: $pagination .= "pg=".$i."\'>".$i."</a>";

     } 

}

$pagination .= "</div>";

Have a nice day!

Amit Kumar
Amit Kumar
1,063 Points

sir please tell me what is the reason of using & at the end of line $pagination .= "cat=".$section."&";