Jump to content

highlight current page number in pagination


vinpkl

Recommended Posts

hi all

 

like the pagination in this forum,

i want to hightlight the page number in my pagination. here is code of for loop which displays page number. i want to apply diferent "style class" to current page and diferent "style class" to other pages.

 

at present all number are coming as same

 

$page = intval($_GET['page']);
    if ($page < 1 || $page > $total_pages) {
        $page = 1;
    }
    $offset = ($page - 1) * $records_per_page;
    
echo "No. of Pages";
    for ($i = 1; $i <= $total_pages; $i++) {
        if ($i == $page) {
            $class = 'class="paging"';
            $prepend = 'Page ';
}
echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";
        unset($class, $prepend);
    
}

 

vineet

Link to comment
Share on other sites

i don't think your outputting your html correctly. your 'echo' statement...

echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";

would result with this...

 

<a href=products-dealerid9class=paging>.... etc,...

 

check your resulting code in the browser. if you use firefox, a very good debugger is called firebug. check it out.

Link to comment
Share on other sites

i don't think your outputting your html correctly. your 'echo' statement...

echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";

would result with this...

 

<a href=products-dealerid9class=paging>.... etc,...

 

check your resulting code in the browser. if you use firefox, a very good debugger is called firebug. check it out.

 

hi fooDigi

 

actually the linking has been done by search engine guy by shortening urls and its working fine. That part he handles.

 

i just need a style class for my pagination with separate class for curent page.

 

at preset i m using

<style type="text/css">
A.paging {background: #FFCC00; text-decoration: none; color:#FFFFFF}
A.paging:visited {background: black; text-decoration: none;  color:#FFFFFF}
A.paging:active {background: #FFCC00; text-decoration: none;  color:#FFFFFF}
A.paging:hover {background: #FFCC00; font-weight:bold; color:#FFFFFF}
</style>

 

but neither it works in IE7 nor FF3. i need something that can be done severside.

 

vineet

Link to comment
Share on other sites

if you have an html code sample of exactly what you need, i may help you with the css.

 

here is my html sample.

if you do in this. i want when i click one link then other links should be of separte link to show that i selected the particular number link.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
A:link {background: #FFCC00; text-decoration: none; color:#FFFFFF}
A:visited {background: black; text-decoration: none;  color:#FFFFFF}
A:active {background: #FFCC00; text-decoration: none;  color:#FFFFFF}
A:hover {background: #FFCC00; font-weight:bold; color:#FFFFFF}
</style>

</head>

<body>
<a href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a>
</body>
</html>

 

or something like the pic i have attached

 

 

vineet

 

[attachment deleted by admin]

Link to comment
Share on other sites

once you click one of the pagination links, the page should "reload" with the new page number, right...

then just assign a css class to the selected number...

 

<style type="text/css">
.selected{background: #ccff00}
</style>

<a href="#">1</a> <a href="#" class="selected">2</a> <a href="#">3</a> <a href="#">4</a>

Link to comment
Share on other sites

once you click one of the pagination links, the page should "reload" with the new page number, right...

then just assign a css class to the selected number...

 

<style type="text/css">
.selected{background: #ccff00}
</style>

<a href="#">1</a> <a href="#" class="selected">2</a> <a href="#">3</a> <a href="#">4</a>

 

hi fooDigi

 

i m not writing my paging or pages manually. its coming with the pagination script. so i cannot manually write class="selected" on the link which user will select.

 

this html sample i gave u because u said u can help me if i provide u with html sample.

 

so tell me how can i implement it in pagination script

<?php
    $page = intval($_GET['page']);
    if ($page < 1 || $page > $total_pages) {
        $page = 1;
    }
    $offset = ($page - 1) * $records_per_page;
    
echo "No. of Pages";
    for ($i = 1; $i <= $total_pages; $i++) {
        if ($i == $page) {
            $class = 'class="paging"';
            $prepend = 'Page ';
}
echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";
        unset($class, $prepend);
}

?>

 

vineet

Link to comment
Share on other sites

to simplify my first response, let's look at this line of code...

echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";

 

for starters, start your "href" attribute out with quotes (href=\")... without them, it may offset other attribute declarations...

 

 

Link to comment
Share on other sites

to simplify my first response, let's look at this line of code...

echo "<a href=products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";

 

for starters, start your "href" attribute out with quotes (href=\")... without them, it may offset other attribute declarations...

 

 

 

hi foodigi

 

if i start my href with \" then where should i close the opeing quotes or slash. can u do in below line

<?php
echo "<a href=\"products-".$dealer_id . $i. $class . ">" .$prepend. $i . "</a>\n";
?>

 

vineet

Link to comment
Share on other sites

just make sure the resulting html works... not sure what the dealer is, but the following should echo something similar...

 

echo "<a href=\"products-".$dealer_id."-".$i.".html\" class=\"$class\">" .$prepend. $i . "</a>\n";

 

"could" result in...

 

 

<a href="products-435-7.html" class="some_css_class">whatever</a>

 

Link to comment
Share on other sites

just make sure the resulting html works... not sure what the dealer is, but the following should echo something similar...

 

echo "<a href=\"products-".$dealer_id."-".$i.".html\" class=\"$class\">" .$prepend. $i . "</a>\n";

 

"could" result in...

 

 

<a href="products-435-7.html" class="some_css_class">whatever</a>

 

 

hi

 

i would like to ask that this you have done to make my html clear that i understood.

but will it make any solution to separately highlight the current selected page number.

 

vineet

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.