Skip to main content
Inspiring
May 11, 2006
Answered

php & query string variables in a url

  • May 11, 2006
  • 1 reply
  • 798 views
I've been scratching my head for a couple days now. What I'm trying to do seems soooooo easy but it doesn't work. Maybe someone can spot my problem in the code.

What I'm doing is breaking a single blob mysql field into multiple "pages" by inserting a code snippet into the field. That part works fine. The url for the page in question with a sample article is
http://208.106.143.80/articles/articles.php?idq=141&cat=4&pg=1

The url contains the article id, article category and page number. At the bottom of the page is the pagination that reloads the page with another "page" of the article. The code for that is:

$totalpages = $total;
if ($totalpages > 1) {
echo "<p style='text-align:right;'><strong>Page:</strong> ";
if ($i > 1) {
echo " <a href='".$_SERVER['PHP_SELF']."?pg=".($i-1)."'><< Prev</a> ";
}
for ($x = 1; $x <= $totalpages; $x++) {
if ($x == $i) {
echo "<strong>[".$x."]</strong> ";
}
else {
echo "<strong><a href='".$_SERVER['PHP_SELF']."?pg=".$x."'>".$x."</a></strong> ";
}
}
if ($i < $total) {
echo " <a href='".$_SERVER['PHP_SELF']."?pg=".$k."'>Next >></a></p>";
}
}

Basically all I'm doing is throwing the new querystring pg=$x to the end of the current page url and reloading the current page. And that is the problem. Even though the page links look right in the browser, it just keeps loading the same "page" over and over again. I can go into the url in the browser and manually change from page 1 to page 2, etc. and that works as it should.

Ideas from anyone smarter than I?

What am I missing here.
This topic has been closed for replies.
Correct answer aerobicdesign
Thanks Micha. That is the missing bit of the puzzle I wasn't getting from my end. I wasn't getting the error. I will work on the script a bit more and see if I can see where I went wrong. If you are still around, I'll send another posting that the file has been changed. Mind you, if I get it fixed, I guess I should see it working and problem solved.
Thanks all. I messed around with the script a bit more and despite the fact that I thought I had already tried adding the missing urlstring values, this time when I did it, it worked like it was supposed to. Problem history.

1 reply

Participant
May 11, 2006
Is it that you are missing the idq and cat variables from the url you generate?

If you type in http://208.106.143.80/articles/articles.php?pg=2 for example, which is an example of a link destination from your page, it doesn't work.
It seems that the idq is essential, but cat isn't.
Inspiring
May 11, 2006
Hi Peter. No, that I can add if need be. But if you go to the link I provided to you below, then go down to the bottom of the page and click on any of the page numbers, eventhough the link appears to be correct (as in the pg=x changes), the page, when it reloads, is still the same page.

It is like something is just eating up the querystring I'm sending to that page.