Forum Moderators: coopster

Message Too Old, No Replies

can any body check my only few lines code "PAGING ISSUE"

paging not working with in if statement

         

mudassir

12:25 pm on Jul 19, 2012 (gmt 0)

10+ Year Member



when i am using simple paging scrip with out using Post value and with out IF statement my query works perfectly but when i am adding _post value thorugh a form i have to use IF statement to get values before runing the query , in this case my paging not working properly when i am pressing Next page button it does not shows any record
please check and correct my coding



<html>
<head><title>Supplier</title>
</head>
<body>
<form method= "post" action="help.php">
<input type ="hidden" name ="submitted" value = "true" />
<input type="text" name="criteria" />
<input type="submit" />
</form>
<?php
if (isset($_POST['submitted']))
{
include('mysql_connect.php');

$per_page = 10;
if(!isset($_GET['page']))
{
$page = 1;
}
else
{
$page = $_GET['page'];
}
if ($page <= 1)
$start = 0 ;
else
$start = $page * $per_page - $per_page;

//$value = '90';
//$sql = "select * from geotex where Buyer = $value ";
//if u run this query and removing above if statement my paging works

$criteria = $_POST['criteria'];
$sql = "select * from geotex where Buyer = $criteria ";


$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = ceil ($num_rows / $per_page) ;
$sql .= " LIMIT $start, $per_page ";
$result = mysql_query($sql);

//to display my result i make a table here
echo "<center>";
echo "<table CELLPADDING=10 border =1>";
echo "<tr> <th>Supplier</th> <th>Buyer</th> <th>PJ_Number</th> <th style='text-align:right'>Quantity</th></tr>";
while ($row = mysql_fetch_array($result))

// my disply re#*$! working perfectly
{
echo "<tr><td>";
echo $row['supplier'];
echo "</td><td>";
echo $row['Buyer'];
echo "</td><td>";
echo $row['PJ_number'];
echo "</td><td style='text-align:right'>";
echo $row['Total_qty'];
echo "</td></tr>";
}
echo "</table>";


$prev = $page - 1 ;
$next = $page + 1 ;

// i just echo next and prev button
echo "<hr>";
if ($prev > 0)
echo "<a href='?page=$prev'>prev</a>";
if ($page < ceil($num_rows/$per_page))
echo "<a href='?page=$next'>next</a>";

// giving page 2 blank in current case
//but with out if statement it works perfectly

}

?>






</body>
</html>

coopster

9:19 pm on Jul 24, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mudassir.

Have you checked the actual value in the HTML source for the next button to see what it contains? And then apply that number to your logic here to see if it ends up being what you expected.

omoutop

11:08 am on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



IF i read your code correctly:
Your prev and next links do not re-post your "criteria" field
So, when you click next/prev, you just send empy post data to your query