我想让id和开始时间与结束时间通过<a href="">升序和降序排列,怎么写,
求大侠帮助
<table border=1 width=800 cellspacing=0 style=border-collapse:collapse> 
<tr style=background-image:url(img/new_hader_27.jpg) height=30 class="chaxun_head"><th>选择</th><th><a href="#" style="text-decoration: underline;">id</a></th><th><a href="#" style="text-decoration: underline;">开始时间</a></th><th><a href="#" style="text-decoration: underline;">结束时间</a></th><th>内容</th><th>备注</th><th>s_type</th><th>操作</th></tr>
<?php
$ziduan = isset($_POST['ziduan'])?$_POST['ziduan']:(isset($_GET['ziduan'])?$_GET['ziduan']:"");
$txt_sousuo = isset($_POST['txt_sousuo'])?$_POST['txt_sousuo']:(isset($_GET['txt_sousuo'])?$_GET['txt_sousuo']:"");$where = "where 1";
if(!empty($ziduan) && !empty($txt_sousuo)){
    $where .= " and $ziduan like '%{$txt_sousuo}%'"; 
}
$sql = "SELECT count(*) as countnum FROM hotel_activities_2 $where";
$result=mysql_fetch_array(mysql_query($sql));
$countnum = $result['countnum'];
if(!$countnum) die("<script>alert('查询的数据不存在');window.location='chaxun.php';</script>");$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);
$sel1 = "SELECT * FROM hotel_activities_2 $where order by h_id limit $start,$rowsPerPage"; 
$result=mysql_query($sel1) or die("查询失败"); 
//循环输出表中各个字段值 
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 '</tr>'; 

echo '<input type=submit value="删除所选" onclick="return delconfirm()"></form>'; 
echo "<div align='left' 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}&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}&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;".""
?>
mysql_close($connection); //关闭与数据库的连接 */

解决方案 »

  1.   

    查询语句修改一下:
    $sel1 = "SELECT * FROM hotel_activities_2 $where order by h_id limit $start,$rowsPerPage Order by start_date, end_date desc"; 
      

  2.   

    语句看错了,你前面已经有oeder了,改成这样好了。
    SELECT * FROM hotel_activities_2 $where order by h_id, start_date, end_date desc limit $start,$rowsPerPage如果你要点击排序的话,要在
        echo '<td>'.date('Y-m-d', strtotime($row['start_date'])).'</td>'; 
        echo '<td>'.date('Y-m-d', strtotime($row['end_date'])).'</td>'; 
    这两个td的onclick事件里面提交排序的查询给后台。
      

  3.   

    请指教
    可这个onclick事件怎么写啊
      

  4.   

    这个onclick事件是不是应该在
    <tr style=background-image:url(img/new_hader_27.jpg) height=30 class="chaxun_head"><th>选择</th><th><a href="#" style="text-decoration: underline;" onclick="">id</a></th><th><a href="#" style="text-decoration: underline;" onclick="">开始时间</a></th><th><a href="#" style="text-decoration: underline;" onclick="">结束时间</a></th><th>内容</th><th>备注</th><th>s_type</th><th>操作</th></tr>应该写在这