Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

// 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

$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 . '';
}

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...