Ghamdan Posted October 3, 2012 Share Posted October 3, 2012 I am practisng how to create pagination in chapter 10 - page: 317 and I want to add class to the current page so I can style it using CSS. When I try to add a class, or use float in CSS, I run into a problem. Can you help me solve this problem? Excerpt of the colde: // Make the links to other pages: if($pages > 1) { echo ' <p id="pagination"> '; $current_page = ($start/$display) + 1 ; // If it is not the first page, make a previous link: if($current_page != 1) { echo ' <a href="view_users.php?s=' . ($start - $display).'&p=' . $pages . '&sort='. $sort . ' "> Previous </a> '; } // Make all the numbered pages: for($i = 1; $i<= $pages; $i++) { if($i != $current_page) { echo ' <a href="view_users.php?s=' . (($display *($i - 1) )). '&p=' . $pages .'&sort='. $sort .' ">' . $i . ' </a> '; } else { echo $i . ''; } }// End of FOR loop. // If it is not the last page, make a next button: if($current_page != $pages) { echo ' <a href="view_users.php?s=' . ($start + $display) . '&p='. $pages . '&sort=' . $sort . ' "> Next </a> '; } echo ' </p>'; }// End of links section. ===================================== Thank you Ghamdan Link to comment Share on other sites More sharing options...
rob Posted October 3, 2012 Share Posted October 3, 2012 You should show the code in which you're actually trying to add the class; you should also state what the problem is. Link to comment Share on other sites More sharing options...
Ghamdan Posted October 3, 2012 Author Share Posted October 3, 2012 // Make the links to other pages: if($pages > 1) { echo ' <p id="pagination"> <span class="current"> '; $current_page = ($start/$display) + 1 .' </span>'; // If it is not the first page, make a previous link: if($current_page != 1) { echo ' <a href="view_users.php?s=' . ($start - $display).'&p=' . $pages . '&sort='. $sort . ' "> Previous </a> '; } // Make all the numbered pages: for($i = 1; $i<= $pages; $i++) { if($i != $current_page) { echo ' <a href="view_users.php?s=' . (($display *($i - 1) )). '&p=' . $pages .'&sort='. $sort .' ">' . $i . ' </a> '; } else { echo $i . ''; } }// End of FOR loop. // If it is not the last page, make a next button: if($current_page != $pages) { echo ' <a href="view_users.php?s=' . ($start + $display) . '&p='. $pages . '&sort=' . $sort . ' "> Next </a> '; } echo ' </p>'; }// End of links section. Link to comment Share on other sites More sharing options...
rob Posted October 3, 2012 Share Posted October 3, 2012 $current_page is used as a flag for the if($i != $current_page) conditional, it's not content sent to the browser. If you want to put a span with class around the current page you need to put it around the content echoed if it is the current page. } else { echo $i . ''; } 1 Link to comment Share on other sites More sharing options...
Ghamdan Posted October 3, 2012 Author Share Posted October 3, 2012 Thank you rob for helping me. The problem has been solved. You are really great. Link to comment Share on other sites More sharing options...
Recommended Posts