-5

below is my pagination code to display pagination It working and also display pages properly.

but the problem is when i click on page2 it generates an error.

now i debug the code...and find prob... problem is the query is not getting where condition .......

for ex-- the pagination generates pages like this...

1-2-3-4-Next-Last

When I click on page2 or page3 or lastpage the query generates error like

Undefined index: city Undefined index: state

The query is not fetching where clause.

plz tell how to resolve this error...

<?php           
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 2;
$startpoint = ($page * $limit) - $limit;
$statement = "news";
mysql_set_charset('utf8'); 
$cit = $_GET['city'];
$sta = $_GET['state'];
$sql="select id,story,headline,photo from {$statement} where state_id = '$sta' and city_id = '$cit' order by id desc LIMIT {$startpoint} , {$limit}";
$query=mysql_query($sql);
?>

<?php echo $Admin->pagination($statement,$limit,$page); ?>
  • Read up about SQL injection and the prevention of it – PeeHaa Dec 20 '14 at 11:39
  • 1
    i placed simple query here but i used sql injection in my query... – saiherbal ingle Dec 20 '14 at 12:13
  • plz suggest solution of above question....... – saiherbal ingle Dec 20 '14 at 12:17
  • 1
    Help on error resolution with a specific PHP error message is part of this: [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982/367456) – hakre Dec 20 '14 at 12:40
  • 1
    also your code does not do any error handling nor do you show the faulty SQL query in case it failed. This just means that you are flying blind. In case of an error you have no clue where and what went wrong. This might be the actual cause why you ask the question here. So improving error handling and actually debugging your code should enable you to find the cause of your problem quickly. – hakre Dec 20 '14 at 12:41

2 Answers2

0

You need to pass city and state values in the query string, in addition to the page, to make the query work.

Thus,

http://localhost/nopagination/?page=-1&city=MyCity+OR+1&state=MyState

exemplary, don't forget to double check all incoming values.

hakre
  • 193,403
  • 52
  • 435
  • 836
Gem
  • 1
  • 1
0

You have to pass city & state variable with pagination url ,
so wherever you click on page2 or page3 it get this 2 variable that is used in where condition.

Ex.

<a href="yourpage.php?page=2&city=cityname&state=statename">2</a>
<a href="yourpage.php?page=3&city=cityname&state=statename">3</a>
<a href="yourpage.php?page=4&city=cityname&state=statename">4</a>
jay.jivani
  • 1,560
  • 1
  • 16
  • 33