排序都正常,但是一翻页或者按尾页,还是原来没排序的数据
$where1 = "where 1";
if(!empty($rizhiziduan) && !empty($txt_ss)){
    $where1 .= " and $rizhiziduan like '%{$txt_ss}%'"; 
}
$sql1 = "SELECT count(*) as countnum FROM hotel_rizhi $where1";
$result1=mysql_fetch_array(mysql_query($sql1));
$countnum = $result1['countnum'];
if(!$countnum) die("<script>alert('查询的数据不存在');window.location='chaxun_rizhi.php';</script>");
/*******************排序*************************/
$field=$_REQUEST["field"];
if($field==""){
$field="id";
}
else{
$field=$_REQUEST["field"];
}$order=$_REQUEST["order"];
if($order==""){
$order="asc";
}
else{
$order=$_REQUEST["order"];
}$rowsPerPage=10; 
$maxPage=ceil($countnum/$rowsPerPage); 
$page=isset($_GET['curPage'])?intval($_GET['curPage']):1; 
$page = $page<1?1:$page;
$page = $page>$maxPage?$maxPage:$page;$start=$rowsPerPage*($page-1);
$sel = "SELECT * FROM hotel_rizhi $where1 order by ".$field." ".$order." limit  $start,$rowsPerPage"; 
$result1=mysql_query($sel) or die("查询失败"); 
/*******************输出表格***************/
echo "<table  border=1 width=700 cellspacing=0 style=border-collapse:collapse id=tbColor>";
echo '<tr style=background-image:url(img/new_hader_27.jpg) height=30 class="chaxun_head">';
echo '<th width=50>'.'选择'.'</th>';
if($order=="asc"){
echo '<th width=120>'.'<a href="?field=hotel_id&order=desc" style="text-decoration: underline;">酒店ID</a>'.'</th>';
}else{
echo '<th width=120>'.'<a href="?field=hotel_id&order=asc" style="text-decoration: underline;">酒店ID</a>'.'</th>';
}
echo '<th width=80>'.'姓名'.'</th>';
echo '<th width=200>'.'内容介绍'.'</th>';
echo '<th width=75>'.'操作'.'</th>';
if($order=="asc"){
    echo '<th width=75><a href="?field=time&order=desc" style="text-decoration: underline;">时间</a></th>';
}else{
echo '<th width=75><a href="?field=time&order=asc" style="text-decoration: underline;">时间</a></th>';
}
echo '</tr>';
//循环输出表中各个字段值 
echo '<form action="delect_rz.php" method=post>'; 
while ($row = mysql_fetch_array($result1)) {
?>
<tr align="center" class="shu">
<td><input type=checkbox name="id[]" value=" <?php echo $row['id'] ?>"></td>
<td><?php echo $row['hotel_id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['content']?></td>
<td><?php echo $row['operating']?></td>
<td><?php echo $row['time']?></td>
</tr>
<?php
}
echo '</form>';
echo '<div align=left>'.'<input type=submit value="删除所选" onclick="return delconfirm()">'.'</div>'; 
echo "<div align=right class=shu><a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=1' style='color:#FF0000'>首页</a>"."&nbsp;&nbsp;";
if($page>1) { 
    $prevPage=($page-1)<1?1:$page-1;
    echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$prevPage'><img src='img/prev.gif'/></a>"; 

echo "&nbsp;"."&nbsp;";
if ($page<$maxPage) { 
    $nextPage=($page+1)>$maxPage?$maxPage:$page+1;
    echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$nextPage'><img src='img/next.gif'/></a>";

echo ""."&nbsp;&nbsp;&nbsp;<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."&nbsp;&nbsp;&nbsp;".""
?>

解决方案 »

  1.   

    $_GET获取排序关键词,然后再下面的链接中在加上就行了 
      

  2.   


    //看看这个<?php
    //=========================================================================================================================
    function p($var){echo '<pre>';if((is_array($var)||is_object($var))&&count($var)){print_r($var);}else{var_dump($var);}exit;}
    //=========================================================================================================================class dbconnect {
        protected $link;
        private $server, $username, $password, $db;
        
        public function __construct($server, $username, $password, $db)    {
            $this->server = $server;
            $this->username = $username;
            $this->password = $password;
            $this->db = $db;
            $this->connect();
        }
        
        private function connect(){
            $this->link = mysql_connect($this->server, $this->username, $this->password);
            mysql_select_db($this->db, $this->link);
        }
        
        public function __sleep(){
            return array('server', 'username', 'password', 'db'); //返回保存的属性
        }
        
        public function __wakeup(){
            $this->connect();
        }
    }$db = new dbconnect('localhost', 'user', 'pass', 'dbname');
    $srlz_db= serialize($db);
    $unsrlz_db= unserialize($srlz_db);
    p($unsrlz_db);?>
      

  3.   


    我都不知道说你什么好了,你在翻页的时候加上order这个参数不就行了吗?这么简单的问题。~~~
      

  4.   


    echo "<div align=right class=shu><a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=1&order=".$order."' style='color:#FF0000'>首页</a>"."&nbsp;&nbsp;";
    if($page>1) { 
        $prevPage=($page-1)<1?1:$page-1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=".$prevPage."&order=".$order."'><img src='img/prev.gif'/></a>"; 

    echo "&nbsp;"."&nbsp;";
    if ($page<$maxPage) { 
        $nextPage=($page+1)>$maxPage?$maxPage:$page+1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=".$nextPage."&order=".$order."'><img src='img/next.gif'/></a>";

    echo ""."&nbsp;&nbsp;&nbsp;<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=".$maxPage."&order=".$order."' style='color:#FF0000'>尾页</a>"."&nbsp;&nbsp;&nbsp;"."";
    你把翻页的这段代码替换一下看看行不行?
      

  5.   

    echo "<table border=1 width=800 cellspacing=0 style=border-collapse:collapse id='tbColor'>";
    echo '<tr style=background-image:url(img/new_hader_27.jpg) height=30 class="chaxun_head">'.'
    <th width=50>'.'选择'.'</th>';
    if($order=="asc"){
    echo '<th width=100>'.'<a href="?field=hotel_id&order=desc" style=text-decoration: underline;">'.'酒店ID'.'</a>'.'</th>';
    }
    else{
    echo '<th width=100>'.'<a href="?field=hotel_id&order=asc" style=text-decoration: underline;">'.'酒店ID'.'</a>'.'</th>';
    }
    if($order=="asc"){
    echo '<th width=100>'.'<a href="?field=start_date&order=desc" style="text-decoration: underline;">'.'开始时间'.'</a>'.'</th>';
    }
    else {
    echo '<th width=100>'.'<a href="?field=start_date&order=asc" style="text-decoration: underline;">'.'开始时间'.'</a>'.'</th>';
    }
    if($order=="asc"){
    echo '<th width=100>'.'<a href="?field=end_date&order=desc" style="text-decoration: underline;">'.'结束时间'.'</a>'.'</th>';
    }
    else{
    echo '<th width=100>'.'<a href="?field=end_date&order=asc" style="text-decoration: underline;">'.'结束时间'.'</a>'.'</th>';
    }
    echo '<th width=200>'.'内容介绍'.'</th>'.'<th width=100>'.'备注'.'</th>'.'<th width=100>'.'s_type'.'</th>'.'<th width=50>'.'操作'.'</th>'.'</tr>';
    $order=$_REQUEST["order"];
    //循环输出表中各个字段值 
    echo '<form action="delect_sj.php" method=post>'; 
    while ($row = mysql_fetch_array($result)) { 
        echo '<tr align="center" class="shu">'; 
        echo '<td><input type=checkbox name="hid[]" value="'.$row['h_id'].'"></td>'; 
        echo '<td>'.$row['hotel_id'].'</td>'; 
        echo '<td>'.date('Y-m-d', strtotime($row['start_date'])).'</td>'; 
        echo '<td>'.date('Y-m-d', strtotime($row['end_date'])).'</td>'; 
        echo '<td>'.$row['content'].'</td>'; 
        echo '<td>'.$row['source'].'</td>'; 
        echo '<td>'.$row['s_type'].'</td>'; 
        echo '<td>'.'&nbsp;<a href="upedit.php?hid='.$row['h_id'].'" >编辑</a>&nbsp;'.'</td>'; } 
    echo '<input type=submit value="删除所选" onclick="return delconfirm()">'.'</tr></form>';
    echo "<div align='right' class='shu'>
    <a href='?ziduan={$ziduan}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=1' style='color:#FF0000'>首页</a>"."&nbsp;&nbsp;";if($page>1) { 
        $prevPage=($page-1)<1?1:$page-1;
        echo "<a href='?ziduan={$ziduan}&order={$order}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$prevPage'><img src='img/prev.gif'/></a>";
    }
    echo "&nbsp;"."&nbsp;";
    if ($page<$maxPage) { 
        $nextPage=($page+1)>$maxPage?$maxPage:$page+1;
        echo "<a href='?ziduan={$ziduan}&order={$order}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$nextPage'><img src='img/next.gif'/></a>";

    echo ""."&nbsp;&nbsp;&nbsp;<a href='?ziduan={$ziduan}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."&nbsp;&nbsp;&nbsp;".""
    ?>
    这样??
      

  6.   

    把所有的href里面都加上order={$order},你这个问题就是因为没有获取这个参数,所以每次翻页以后排序都是按照默认的排序,你要是还不明白,加我qq吧,357430382
      

  7.   

    <a href="?field=hotel_id&order=desc"
    <a href="?field=hotel_id&order=asc"
    <a href="?field=start_date&order=desc"
    <a href="?field=end_date&order=asc"
    这些没有传递查询条件和页号<a href='?ziduan={$ziduan}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=1' 
    <a href='?ziduan={$ziduan}&order={$order}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$prevPage'
    "<a href='?ziduan={$ziduan}&order={$order}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$nextPage'
    <a href='?ziduan={$ziduan}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$maxPage'
    这些没有传递排序字段和方式
      

  8.   

    echo '<th width=50>'.'选择'.'</th>';
    if($order=="asc"){
    echo '<th width=120>'.'<a href="?field=hotel_id&order=desc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">酒店ID</a>'.'</th>';
    }else{
    echo '<th width=120>'.'<a href="?field=hotel_id&order=asc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">酒店ID</a>'.'</th>';
    }
    echo '<th width=80>'.'姓名'.'</th>';
    echo '<th width=200>'.'内容介绍'.'</th>';
    echo '<th width=75>'.'操作'.'</th>';
    if($order=="asc"){
        echo '<th width=75><a href="?field=time&order=desc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">时间</a></th>';
    }else{
    echo '<th width=75><a href="?field=time&order=asc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">时间</a></th>';
    }
    echo '</tr>';
    $order=$_REQUEST["order"];
    //循环输出表中各个字段值 
    echo '<form action="delect_rz.php" method=post>'; 
    while ($row = mysql_fetch_array($result1)) {
    ?>
    <tr align="center" class="shu">
    <td><input type=checkbox name="id[]" value=" <?php echo $row['id'] ?>"></td>
    <td><?php echo $row['hotel_id']?></td>
    <td><?php echo $row['name']?></td>
    <td><?php echo $row['content']?></td>
    <td><?php echo $row['operating']?></td>
    <td><?php echo $row['time']?></td>
    </tr>
    <?php
    }
    echo '</form>';
    echo '<div align=left>'.'<input type=submit value="删除所选" onclick="return delconfirm()">'.'</div>'; 
    echo "<div align=right class=shu><a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=1' style='color:#FF0000'>首页</a>"."&nbsp;&nbsp;";
    if($page>1) { 
        $prevPage=($page-1)<1?1:$page-1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&order={$order}&txt_ss=".rawurlencode($txt_ss)."&curPage=$prevPage'><img src='img/prev.gif'/></a>"; 

    echo "&nbsp;"."&nbsp;";
    if ($page<$maxPage) { 
        $nextPage=($page+1)>$maxPage?$maxPage:$page+1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&order={$order}&txt_ss=".rawurlencode($txt_ss)."&curPage=$nextPage'><img src='img/next.gif'/></a>";

    是这样加么
      

  9.   

    我这段加什么查询条件啊,这段又不是翻页
    <a href="?field=hotel_id&order=desc"
    <a href="?field=hotel_id&order=asc"
    <a href="?field=start_date&order=desc"
    <a href="?field=end_date&order=asc"
      

  10.   

    $field=$_REQUEST["field"];
    if($field==""){
    $field="id";
    }
    else{
    $field=$_REQUEST["field"];
    }$order=$_REQUEST["order"];
    if($order==""){
    $order="asc";
    }
    else{
    $order=$_REQUEST["order"];
    }$rowsPerPage=10; 
    $maxPage=ceil($countnum/$rowsPerPage); 
    $page=isset($_GET['curPage'])?intval($_GET['curPage']):1; 
    $page = $page<1?1:$page;
    $page = $page>$maxPage?$maxPage:$page;$start=$rowsPerPage*($page-1);
    $sel = "SELECT * FROM hotel_rizhi $where1 order by ".$field." ".$order." limit  $start,$rowsPerPage"; 
    $result1=mysql_query($sel) or die("查询失败"); 
    /*******************输出表格***************/
    echo "<table  border=1 width=700 cellspacing=0 style=border-collapse:collapse id=tbColor>";
    echo '<tr style=background-image:url(img/new_hader_27.jpg) height=30 class="chaxun_head">';
    echo '<th width=50>'.'选择'.'</th>';
    if($order=="asc"){
    echo '<th width=120>'.'<a href="?&order=$order&field=hotel_id&order=desc" style="text-decoration: underline;">酒店ID</a>'.'</th>';
    }else{
    echo '<th width=120>'.'<a href="?&order=$order&field=hotel_id&order=asc" style="text-decoration: underline;">酒店ID</a>'.'</th>';
    }
    echo '<th width=80>'.'姓名'.'</th>';
    echo '<th width=200>'.'内容介绍'.'</th>';
    echo '<th width=75>'.'操作'.'</th>';
    if($order=="asc"){
        echo '<th width=75><a href="?field=time&order=desc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">时间</a></th>';
    }else{
    echo '<th width=75><a href="?field=time&order=asc&rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."" style="text-decoration: underline;">时间</a></th>';
    }
    echo '</tr>';
    $order=$_REQUEST["order"];
    //循环输出表中各个字段值 
    echo '<form action="delect_rz.php" method=post>'; 
    while ($row = mysql_fetch_array($result1)) {
    ?>
    <tr align="center" class="shu">
    <td><input type=checkbox name="id[]" value=" <?php echo $row['id'] ?>"></td>
    <td><?php echo $row['hotel_id']?></td>
    <td><?php echo $row['name']?></td>
    <td><?php echo $row['content']?></td>
    <td><?php echo $row['operating']?></td>
    <td><?php echo $row['time']?></td>
    </tr>
    <?php
    }
    echo '</form>';
    echo '<div align=left>'.'<input type=submit value="删除所选" onclick="return delconfirm()">'.'</div>'; 
    echo "<div align=right class=shu><a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=1' style='color:#FF0000'>首页</a>"."&nbsp;&nbsp;";
    if($page>1) { 
        $prevPage=($page-1)<1?1:$page-1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$prevPage'><img src='img/prev.gif'/></a>"; 

    echo "&nbsp;"."&nbsp;";
    if ($page<$maxPage) { 
        $nextPage=($page+1)>$maxPage?$maxPage:$page+1;
        echo"<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$nextPage'><img src='img/next.gif'/></a>";

    echo ""."&nbsp;&nbsp;&nbsp;<a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."&nbsp;&nbsp;&nbsp;".""
    ?>
      

  11.   

    $sel = "SELECT * FROM hotel_rizhi $where1 order by ".$field." ".$order." limit  $start,$rowsPerPage"; 
    你是不翻页,但是sql指令中的 $where1 $start $rowsPerPage 如何取值?