Skip to main content
April 11, 2010
Answered

Passing a value between pages during navigation

  • April 11, 2010
  • 2 replies
  • 2517 views

Hello all,

To the point: Selecting an option on the first page passes the query string value, in this case, 11, to the next page.

The next page presents numerous bits of data, in this case short prargraphs. There are only three paragraphs shown per page, and a navigation system is in place to allow the user to go back and forth between these groups of paragraphs.

It all works seamlessly.

What I want to ADD is the ability to pass the original query string value along (11) each time the user goes forward or back using the navigation links.

The navigation system is PHP and reloads the same page with the appropriate data.

I just want to pass a value along...how?

Thanks in advance!

Sincerely,

wordman

This topic has been closed for replies.
Correct answer

STOP THE PRESSES...I GOT IT!

Michael,

You were right, I just, as usual, didn't provide enough info.

These were my original navlinks:

echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'"> Back </a>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'"> Next </a>';

All I had to do was implement your suggestion properly into my code. The navlinks are contained inside php tags, so all I had to do was amend the links thus:

echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&ct='.($spec).' "> Back </a>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'&ct='.($spec).' "> Next </a>';

And voila, the code WORKS, it carries the original query string back and forth DELIGHTFULLY, which then helps to keep my title and header information in place during navigation. Here's the complete navcode:

<div id="header4">
    <p>Displaying <?php echo $startRow+1;
          if ($startRow+1 < $galTotal) {
            echo ' to ';
            if ($startRow+SHOWMAX < $galTotal) {
              echo $startRow+SHOWMAX;
              }
            else {
              echo $galTotal;
              }
            }
          echo " of $galTotal";
          if ($curPage > 0) {
                      echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'&ct='.($spec).' "> Back </a>';
                      }
          if ($startRow+SHOWMAX < $galTotal) {
                      echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'&ct='.($spec).' "> Next </a>';
                      }
          ?> &#183; <a href="categories.php?c=1">Categories</a> &#183; <a href="main.php">Home</a></p></div>

I owe you big time. Not only you but Bregent as well. Your constant support and suggestions led me to figuring this out.

YOURE ALL AWESOME!!!

Most sincerely,

wordman


Anytime, man.

2 replies

Participating Frequently
April 12, 2010

You don't need to use a cookie if you don't want. Your script would simply need to read the query string value and then append it to the navigation links.

April 12, 2010

Bregent,

Thanks for the quick reply. I just posted a detailed description of what is going on for me. Passing the query string from one page to another isn't a problem, but passing it when scrolling through subsets of records that are updated on the same page IS.

Cheers,

wordman

Participating Frequently
April 12, 2010

>but passing it when scrolling through subsets of

>records that are  updated on the same page IS.

Sorry, I still don't understand why that would be a problem. Any value that is available within a script, is available to be appended to a querystring. Please explain why this won't work.

April 11, 2010

Seems to me the easiest way is to set a $_COOKIE with this value at the beginning.

April 11, 2010

Michael,

Many thanks for that. I have researched this extensively and (with my relative newcomer's knowledge and skill level) it is looking as though using cookies and sessions is my only hope.

I wanted to put out a general question: Do professional developers even think twice before using sessions and cookies nowadays? I remember years ago when a lot of people disabled cookies in their browsers, and today it seems as though that limits one's navigation of the net something fierce.

I wasn't sure if I should go the session/cookie route, if my users didnt have theirs switched on, they would not be able to access my galleries.

Please, I'd love to hear everyone's thoughts on this matter.

Sincerely,

wordman

April 12, 2010

It's pretty safe to use cookies, nowadays. Most people have cookies enabled, and those who don't are probably very used to having problems on various sites.

He's right, you don't HAVE to use cookies in this case, but I was just thinking that it would be the simplest option in this particular circumstance.