Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php & query string variables in a url

Explorer ,
May 11, 2006 May 11, 2006
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.
TOPICS
Server side applications
813
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 12, 2006 May 12, 2006
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.
Translate
New Here ,
May 11, 2006 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 11, 2006 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2006 May 12, 2006
.oO(aerobicdesign)

>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.

The response from the server is somewhat broken. In some browsers this
might lead to a reload of the current page, in others like Opera and
Lynx you'll get a "Object Moved" response instead, containing a link to
the same page.

This is your posted link:

http://208.106.143.80/articles/articles.php?idq=141&cat=4&pg=1

These are the links at the bottom of that article:

http://208.106.143.80/articles/articles.php?pg=2
http://208.106.143.80/articles/articles.php?pg=3

But of course this won't work.

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

No, you're just not creating a complete query string. The article and
category IDs are missing, so the script doesn't know what to display.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2006 May 12, 2006
Thanks guys. I realize that it is an incomplete url string. If you click on the page links at the bottom of the article, are you actually getting a 404 error or is it just coming back to the same original page that you started from?

The problem I'm having is that even if I add the article id and category to the url string, the page just keeps reloading with the same urlstring thing and I can't seem to update it to a new value.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2006 May 12, 2006
.oO(aerobicdesign)

>Thanks guys. I realize that it is an incomplete url string. If you click on the
>page links at the bottom of the article, are you actually getting a 404 error
>or is it just coming back to the same original page that you started from?

The server returns a 302 status code, which is usually used to redirect
the browser to another page. But it doesn't tell where to redirect to,
so some browsers will simply "redirect" to the current page again, while
others show the plain message received from the server:

| Object Moved
| This document may be found here

The word "here" is an empty link.

There's something wrong with your script I guess. If some parameters are
missing (like article ID for example) it should return an error message
or something like that.

> The problem I'm having is that even if I add the article id and category to
>the url string, the page just keeps reloading with the same urlstring thing and
>I can't seem to update it to a new value.

Can you upload your updated script? If you include the missing IDs it
should work as expected.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2006 May 12, 2006
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2006 May 12, 2006
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines