paging using a recordset

I have a web page that gets a listing of items from a database.  We want to have only 5 records displayed on a page at a time.  So I calculate the amount of pages and they get them at the top to click on to jump to a certain page.  There are also a few other variables that could be passed that were used to narrow down the listing.
We also have prev and next buttons.

So here's what is wanted.  When a user clicks a page number, they are jumped to that page.  Also, the link changes to the clicked link color.  When the prev and next buttons are used, they go to the correct page, but the link colors on the page numbers don't change.  So what is wanted is to have the page number color change to the clicked link color even if they got to that page by prev/next.

So if I have 1 2 3 4 and you click on 2, it changes from blue to purple in this case.
If you then click next you are on page 3 but it doesn't change to purple.
The code I use is here:

     if($Spage > 0 ){
           print("<a href=\"commercial_new.php?passpage=" . ($Spage - 1) . "&passnext=" . ((5*($Spage + 1))) . "&body_style=" . $Commercial_NEW . "&Commercial_NEW=" . $Commercial_NEW . "\">" . Prev . "</a> |");
                                                       <?php for($y=0;$y<($Stotal/5);$y=$y+1){
   print("<a href=\"commercial_new.php?passpage=" . ($y) . "&passnext=" . ((5*$y)) . "&body_sytle=" . $Commercial_NEW . "&Commercial_NEW=" . $Commercial_NEW . "\">" . ($y + 1) . "</a> | ");
                                           if(($Spage + 1)*5 < $Stotal){
     print("<a href=\"commercial_new.php?passpage=" . ($Spage + 1) . "&passnext=" . ((5*($Spage + 1))) . "&body_style=" . $Commercial_NEW . "&Commercial_NEW=" . $Commercial_NEW . "\">" . NEXT . "</a>");

Who is Participating?
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
Using a style sheet would fix this the quickest.

Using the a:hover, a:visited settings.

You can put the style inline, or in a sheet.

<a href="..." class="non_visited_link">....</a>

and in the style sheet you would have

a:link { color : #000000; }
a.non_visited_link:visited { color : #000000; }

This would then allow the hover and active colours to be the same (I've never seen the active colour used outside of framesets!).


Richard Quadling.
Generally speaking (though it may be browser specific) any link will be considered "visited" if that exact URL (including parameters) has been visited before  (and hence show as purple in the standard colour scheme).

What this probably indicates is some small difference in the way the links are defined.

I did notice one typo in your code, where you have "body_sytle" instead of "body_style" ... is this where it goes wrong?

Other than that just check exactly what the link is either by hovering and reading it from the status bar, or more precisely by doing a "View Source" on the generated page.
mindarchAuthor Commented:
thanks for the spelling catch!  I understand what you are saying about the links.  That's why I'm confused as to why this doesn't work or what I can do.  i have other pages with same set up for coding and they don't work either, no spelling errors.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.


I did some simple tests and they seemed to work okay.  What browser are you viewing in?  IE, Netscape..., or an embedded one?  Which version?

As I said in my initial comment it may be something browser specific, but I'm inclined to think it is just some subtle difference in the URL.

For the browser to recognise the link as visited they must be ABSOLUTELY identical!

What you must realise is that the problem lies in what the browser receives ... therefore the PHP source is somewhat irrelevant except in that it produces the page.  Your answer will lie in looking at the actual source in the browser.

Can you load the page in your browser, and then post the relevant section of the result?
p.s. Some notes on coding...

No need for a ';' after the closing '}' of a block.

Consider using "$y++' rather than "$y = $y + 1".
I did  little testing, after faking a few of the input variables, and I think I may have identified the problem.

It's not clear to me from your code what the "passnext" parameter is for, but this seems to be different for "Prev" as opposed to clicking on the page number link.

I suspect it's the old "copy and paste" trap.

Look at the code that does the link for "Prev".  I think this part ...
  "&passnext=" . ((5*($Spage + 1)))
... should be ...
  "&passnext=" . ((5*($Spage - 1)))

The only other thing I can think of is that the value of Commercial_NEW changes from page to page, in which case the URL will be different and the browser will consider the link to have not been visited.

You may need to consider simplifying the URLs by passing fewer parameters.  Using sessions might provide a good solution for retaining the additional information.
Richard QuadlingSenior Software DeveloperCommented:
Have I missed something?

Using CSS, you can set the colour of links, be they unvisited, active, hover or visited! Any browser that understands CSS supports this very simple method. It will not matter what the URL is.

The reason I have the ; before } is that I use CSS generators which always do so.

mindarchAuthor Commented:
This worked and did what the client wanted.
Richard - the comment regarding ';' was to mindarch refering to PHP, not to do with CSS.

I am a bit surprised at the answer accepted, after all the question stated "Also, the link changes to the clicked link color. " which I thought was the issue here.  

I.e. that it was desirable for the link to change colour when visited.

Is the style sheet just making it so that no links show as visited?
Richard QuadlingSenior Software DeveloperCommented:
In a style sheet, you can usually use the tags as identifies for the formatting/style you want to apply.

a { color : red; }

This will set all anchors to red.

Anchors have some pseudo properties


You can set the colours here and all links will behave as specified.

But in this case, there are 2 links that need to behave differently to the others.

For simplicity, I did not alter the standard links, only the 2 special ones. That was achieved by adding a class property to the required anchors.

<a class="special" ...

a.special:link { color : #000000; }
a.special:visited { color : #000000; }

This will set the unvisited and visited colours to black on text links that are classed as special.

I hope that makes sense!

mindarchAuthor Commented:
I knew that links should change color if they were identical, hence my confusion because on the page they are identical when you view them before clicking.  Making the style sheet change made it work to what the client wanted.  That's the end result.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.