Skip to main content
Known Participant
April 10, 2010
Question

Can't set or retreive a $_GET variable

  • April 10, 2010
  • 1 reply
  • 631 views

I have a problem setting up and passing a variable in a search screen with paging..

I set up the variable like so

$townstr = sprintf("&townstr='%s'", $searchTown);              

This variable is then added to the URL string when I click on the 'Next page';

<a href="<?php printf("%s?pageNum_Get1=%d%s%s%s", $currentPage1, min($totalPages_Get1, $pageNum_Get1 + 1), $queryString_Get1,$tabstr,$townstr); ?>"> Next</a>   


The problem in, when the page is loaded again to show the next screen, the $_GET variable $_GET['townstr'] is always empty,

Any Ideas why it is not being set up.

I displayed it straight after the href code and can't access it, although it's definitely there, as I can see it as part of the URL when I move over the link when running the program.

This topic has been closed for replies.

1 reply

April 10, 2010

I'm not totally familiar with the code you're using (that doesn't mean it's wrong - there's plenty I don't know.)  But can you tell me what it is that you're trying to accomplish? What's the abstract idea?

harkusaAuthor
Known Participant
April 10, 2010

Basically, it's a search page which displays my database records according to which criteria is selected, e.g. 'town = newcastle'. (These are input using the $POST method)

It has a paging function which passes URL parameters when selecting Next page or Previous Page. (using the $_GET command).

The problem is, when the Next/Previous page is selected, the town is lost because it is not included in the HREF string.

I added the town to the string, but can't retreive it using the $_GET, so basically every time I use Next/Previous page, the search is incorrect as it is missing the town from the criteria

harkusaAuthor
Known Participant
April 16, 2010

That's a little confusing to me... once the recordset has been returned, the paging links should only be updating the display of the results that have already been returned.

When I've done things like this, an events list for an organization for example, I would set the query like

SELECT date, event, start_time

FROM events
WHERE some_field = some_variable

Then, I create a repeating table showing, say, only 5 records at a time... then I just go to the "recordset paging" button and insert whatever "Next/Last/First/Previous" links that I want... as I page through the pages, it doesn't "forget" the search criteria, because that has already been set by the query.

I realize I'm not answering your question, it just seems like what you're talking about shouldn't be happening. And the fact that it is seems to indicate something else may be going on.

By the way, my "NEXT" button (on the first page of results) URL looks like this (this was set automatically by DW):

mypage.php?pageNum_Recordset1=1&totalRows_Recordset1=24


Problem solved

The URL parameter that sets up the default tabbed panel (tabst) needed to go on the end of my URL string....

<a href="<?php printf("%s?pageNum_Get1=%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", $currentPage1, min($totalPages_Get1, $pageNum_Get1 + 1), $queryString_Get1, $townstr, $makestr, $modelstr, $countrystr,$bodystr, $neckstr, $boardstr, $pickupsstr, $memberstr, $postcodestr, $colourstr, $offersstr,$valuestr,$valueconditionstr, $yearstr, $yearconditionstr, $conditionstr, $selectorderstr,$selectascdescstr,$tabstr ); ?>"> Next</a>  

It works fine now with all the other parameter passed correctly: