Jump to content

Recommended Posts

Hi,
I'm working on a script that will paginate results of a query submitted by a form. Basically, I have the query
"SELECT * FROM property WHERE City ='$city' AND Rooms='$rooms'

the two variables $rooms and $city are passed to the script from a preceding search form. Everything works ok until i seek to paginate the results, to reduce the pages sizes.
I know where the problem is, it's just trying to get around it that's causing me problems! What's happening is once a user clicks to view the next page, I receive the error:

Notice: Undefined index: City in C:\Server\Apache2\htdocs\Test2\search_basic.php on line 34

I understand that this is because the form is not used to pass the data onto the PHP script once i open the next page, so I added the following to my script

if ($pageno != 1){
$city = $_GET['City'];
$rooms = $_GET['Rooms'];
}
else
{
$city = $_REQUEST['City'];
$rooms = $_REQUEST['Rooms'];
}

and made my page navigation links:

<a href='search_basic.php?pageno=$nextpage?City=$city?Rooms=$rooms'>NEXT</a>

I thought that this would then pass the values for City and Rooms on from the hyperlink back into the script, as it realises that the page number is no longer 1 (i've checked this using an echo). I think the problem in passing the values on, but i'm fairly new to PHP so i'm struggling to find a workaround

Any ideas?
Thanks for your assistance,
Nick

Link to comment
https://forums.phpfreaks.com/topic/18289-mysql-result-pagination-problem/
Share on other sites


hi
  the problem may be in passing the variable

u r using "<a href='search_basic.php?pageno=$nextpage?City=$city?Rooms=$rooms'>NEXT[/url]"

it should be use '&' instead of '?' after the first parameter
eg like

" search_basic.php?pageno=$nextpage&City=$city&Rooms=$rooms "

<a href='search_basic.php?pageno=$nextpage&amp;City=$city&amp;Rooms=$rooms'>NEXT</a>

[nobbc]Your problem is that you were using ? between all the variables.  you need to use a ? after the base php file and then & between everything else.  And &amp; is what you should be using for valid markup.  That is the HTML equivalent of the ampersand.[/nobbc]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.