Jump to content


This topic is now archived and is closed to further replies.


MySQL result pagination problem

Recommended Posts

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'];
$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,

Share this post

Link to post
Share on other sites

  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 "

Share this post

Link to post
Share on other sites
<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]

Share this post

Link to post
Share on other sites


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.