我在显示SQL结果时遇到问题。
我有两个变量必须在搜索数据库之前收到它们的值。
我想在数据库中搜索并使用简单的分页显示结果。 我试过这里的一些代码是第一次运行良好,但是当你移动到下一页时没有显示下一个结果。 我认为当你再次加载页面时,值变量变为null。 index.php发送变量值(用户的选择是什么) index1.php带有分页的结果 这个完整的index1代码:
<?
$dtype = $_POST['dtype'];
$city = $_POST['city'];
$cor = mysql_query(" SELECT * FROM drivers WHERE dtype='$dtype' AND city='$city' " );
$pr=mysql_fetch_array($cor);
$orderid = $pr[ID];
if (!empty($city)) {
$rec_limit = 2;
/* Get total number of records */
$sql = "SELECT count(ID) FROM drivers WHERE dtype='$dtype' AND city='$city' ";
$retval = mysql_query( $sql );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT ID, dname, dtype,mobile,city ".
"FROM drivers WHERE dtype='$dtype' AND city='$city'".
"LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql);
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
?>
<ul data-role='listview' data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'>
<div data-role="footer">
<ul data-role="listview" data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'>
<li>ID : <?echo $row[ID];?></li>
<li>NAME : <?echo $row[dname];?></li>
<li>TYPE : <?echo $row[dtype];?></li>
<li>CITY : <?echo $row[city];?></li>
</ul>
<?
$sid = $row[ID];
}
if( $page > 0 )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$page\""?>data-ajax="false" class="ui-btn ui-corner-all ui-btn-inline ui-mini footer-button-right ui-btn-icon-right ui-icon-carat-l"> Next </a><?
echo "<a href=\"$_PHP_SELF?page=$last\""?>data-ajax="false" class="ui-btn ui-corner-all ui-btn-inline ui-mini footer-button-right ui-btn-icon-right ui-icon-carat-r"> Previous </a><?
}
else if( $page == 0 )
{
echo "<a href=\"$_PHP_SELF?page=$page\"" .$city.""?>data-ajax="false" class="ui-btn ui-corner-all ui-btn-inline ui-mini footer-button-right ui-btn-icon-right ui-icon-carat-l"> Next </a><?
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last </a>";
}
}
else{
echo '
<ul data-role="listview">
<li> can not view records </li>
</ul>
';}
?>