views:

128

answers:

2

two questions:

--1-- it displays all the number of pages. but i'd like it to display as:

<< Prev . . 3 4 [5] 6 7 . . Next >>

--2-- when i hover on the current page no, it should change color or increase the font-size, but when i modify the css of a:hover, all the page nos change color or size instead of the one which i'm pointing to. also, when modifying a:active, nothing happens.

this is my paging code in php:

 $self = $_SERVER['PHP_SELF'];
            $limit = 2; //Number of results per page
            $numpages=ceil($totalrows/$limit);

            $query = $query." ORDER BY idQuotes LIMIT " . ($page-1)*$limit . ",$limit";
            $result = mysql_query($query, $conn)
             or die('Error:' .mysql_error());
?>

<div class="caption">Search Results</div>
<div class="center_div">
<table>
    <?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) {
        $cQuote =  highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
        ?>
        <tr>
        <td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td>
            <td style="font-size:16px;"><?php echo $cQuote; ?></td>
            <td style="font-size:12px;"><?php h($row['vAuthor']); ?></td>
            <td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td>
        </tr>
    <?php } ?>
</table>
</div>

<div class="searchmain">
<?php
   //Create and print the Navigation bar
       $nav="";
       $next = $page+1;
       $prev = $page-1;
       if($page > 1) {
            $nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$prev'); return false;\" href=\"$self?page=" . $prev . "&q=" .urlencode($search_result) . "\">< Prev</a></span>";

            $first = "<span class=\"searchpage\"><a onclick=\"showPage('','1'); return false;\" href=\"$self?page=1&q=" .urlencode($search_result) . "\"> << </a></span>" ;
        }

        else {
            $nav .= "&nbsp;";
            $first = "&nbsp;";
        }

       for($i = 1 ; $i <= $numpages ; $i++) {
            if($i == $page) {
                $nav .= "<span class=\"searchpage\">$i</span>";
            }else{
                $nav .= "<span class=\"searchpage\"><a onclick=\"showPage('',$i); return false;\" href=\"$self?page=" . $i . "&q=" .urlencode($search_result) . "\">$i</a></span>";
            }
        }

        if($page < $numpages) {
            $nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$next'); return false;\" href=\"$self?page=" . $next . "&q=" .urlencode($search_result) . "\">Next ></a></span>";

            $last = "<span class=\"searchpage\"><a onclick=\"showPage('','$numpages'); return false;\" href=\"$self?page=$numpages&q=" .urlencode($search_result) . "\"> >> </a></span>";
        }

        else {

             $nav .= "&nbsp;";
             $last = "&nbsp;";
        }


        echo  $first . $nav . $last;
?>

</div>

and this is how it displays currently:

alt text

css:

.searchmain {
    margin:30px;
    text-align: center;
}
.searchpage {
   border: solid 1px #ddd;
   background: #fff;
   text-align:left;
   font-size: 16px;
   padding:9px 12px;
   color: #FEBE33;
   margin-left:2px;
}

.searchpage a{
    text-decoration: none;
    color: #808080;
}

.searchpage a:hover {
    color: #FEBE33;
    border-color: #036;
    text-decoration: none;
}

.searchpage a:visited {
    color: #808080;
}
A: 

1. Change the padding and border properties of this CSS:

.searchpage {
   border: none;
   background: #fff;
   text-align:left;
   font-size: 16px;
   padding:3px;
   color: #FEBE33;
   margin-left:2px;
}

And add the codes for square brackets around $i.

for($i = 1 ; $i <= $numpages ; $i++) {
            if($i == $page) {
                $nav .= "<span class=\"searchpage\">&#91;$i&#93;</span>";

That should change the visuals of your numbers, I haven't tested it seeing as you don't have a live site but it should work.

2. Instead of .searchpage a:hover try searchmain a:hover.

None of this is tested, but best I could come up with after viewing your code. Hope it helps to at least point you in the right direction :)

Kyle Sevenoaks
kyle, thanks for your response. appreciated. :) however, you misunderstood my first question. perhaps, i haven't been clear (sorry!). i meant, that since the pagination displayed all number of pages from 1 to 8, i wanted it to display only 2 on either side of the current page. ie. if it is on page 5, it should display 3,4 on the left side and 6,7 on the right; instead of displaying all the page numbers. i posted the css for the second part of the question - i tried your second solution, didn't work.
fuz3d
Aha, my mistake. Well I'll try to see how to make what you're after.
Kyle Sevenoaks
+1  A: 

The solution to your first program seems pretty straightforward; you know the number of surrounding links you want to display so you can simply loop from current_page - surrounding_links to current_page + surrounding_links. Add some conditions for the beginning, the end and for when to show the dots and you're done.

For the css; I´m not entirely sure what you want to achieve but I think you can solve it by using just a tags, the surrounding spans seem redundant, you only need them for the items that are not links (.no_link in the example below):

a, .no_link {
    float: left;
    display: block;
    padding:9px 12px;
    border: solid 1px #ddd;
    background: #fff;
    text-align:left;
    font-size: 16px;
}
a {
    color: #808080;
}
a:hover {
    color: #FEBE33;
    border-color: #036;
}
.no_link {
    color: #FEBE33;
}
jeroen
thank you so much!the reason why i was using span was because i've other forms on the same page and i did not want their css to over-ride each other.
fuz3d