?
Solved

paging using a recordset

Posted on 2002-06-17
12
Medium Priority
?
194 Views
Last Modified: 2008-03-06
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:

<?php
     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>");
                                                       };
                                                       ?>

0
Comment
Question by:mindarch
  • 6
  • 3
  • 3
12 Comments
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7084449
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.
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 400 total points
ID: 7088345
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!).

Regards,

Richard Quadling.
0
 

Author Comment

by:mindarch
ID: 7090460
Hamlet,
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7091142
Hmmm...

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?
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7091156
p.s. Some notes on coding...

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

Consider using "$y++' rather than "$y = $y + 1".
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7091177
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)))

0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7091191
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.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7092090
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.

Richard.
0
 

Author Comment

by:mindarch
ID: 7092358
This worked and did what the client wanted.
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7094239
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?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7095322
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

a:hover
a:visited
a:active
a:link

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!

Richard.
0
 

Author Comment

by:mindarch
ID: 7095699
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.

Stephen
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question