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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...