Jump to content


MySQL result pagination problem

  • Please log in to reply
3 replies to this topic

#1 nickd_101

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 22 August 2006 - 11:23 AM

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,

#2 logu

  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 22 August 2006 - 12:09 PM

  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 "

#3 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 22 August 2006 - 12:10 PM

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

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.

Info: PHP Manual

#4 nickd_101

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 22 August 2006 - 12:34 PM

Thanks for the help.
Worked perfectly!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users