这段代码怎样在翻页连接里写排序关键字

xinshou_php 2010-08-26 10:36:01
排序都正常,但是一翻页或者按尾页,还是原来没排序的数据
$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>"."  ";
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 " "." ";
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 ""."   <a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."   ".""
?>
...全文
132 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
我这段加什么查询条件啊,这段又不是翻页
<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"
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
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>"."  ";
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 " "." ";
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>";
}
是这样加么
moths 2010-08-26
  • 打赏
  • 举报
回复
嗯,就这么个意思,还就是搞不懂了,你想什么呢?跟你说的这么清楚了都
moths 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 xuzuning 的回复:]
<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='?zidua……
[/Quote]


那你全部都加上不就行了!!!真服了~~
xuzuning 2010-08-26
  • 打赏
  • 举报
回复
<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'
这些没有传递排序字段和方式
moths 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xinshou_php 的回复:]
PHP code
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">'.'
<t……
[/Quote]
把所有的href里面都加上order={$order},你这个问题就是因为没有获取这个参数,所以每次翻页以后排序都是按照默认的排序,你要是还不明白,加我qq吧,357430382
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
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>'.' <a href="upedit.php?hid='.$row['h_id'].'" >编辑</a> '.'</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>"."  ";

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 " "." ";
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 ""."   <a href='?ziduan={$ziduan}&txt_sousuo=".rawurlencode($txt_sousuo)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."   ".""
?>

这样??
moths 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xinshou_php 的回复:]
引用 5 楼 moths 的回复:
引用 4 楼 xinshou_php 的回复:
引用 3 楼 kyzy_yy_pm 的回复:
2楼的发错了

大哥 ,帮忙改改好吗,谢谢


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

大哥我试过 不行的
[/Quote]

echo "<div align=right class=shu><a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=1&order=".$order."' style='color:#FF0000'>首页</a>"."  ";
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 " "." ";
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 ""."   <a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=".$maxPage."&order=".$order."' style='color:#FF0000'>尾页</a>"."   "."";


你把翻页的这段代码替换一下看看行不行?
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 moths 的回复:]
引用 4 楼 xinshou_php 的回复:
引用 3 楼 kyzy_yy_pm 的回复:
2楼的发错了

大哥 ,帮忙改改好吗,谢谢


我都不知道说你什么好了,你在翻页的时候加上order这个参数不就行了吗?这么简单的问题。~~~
[/Quote]
大哥我试过 不行的
moths 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xinshou_php 的回复:]
引用 3 楼 kyzy_yy_pm 的回复:
2楼的发错了

大哥 ,帮忙改改好吗,谢谢
[/Quote]

我都不知道说你什么好了,你在翻页的时候加上order这个参数不就行了吗?这么简单的问题。~~~
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kyzy_yy_pm 的回复:]
2楼的发错了
[/Quote]
大哥 ,帮忙改改好吗,谢谢
kyzy_yy_pm 2010-08-26
  • 打赏
  • 举报
回复
2楼的发错了
kyzy_yy_pm 2010-08-26
  • 打赏
  • 举报
回复

//看看这个

<?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);

?>
kyzy_yy_pm 2010-08-26
  • 打赏
  • 举报
回复
$_GET获取排序关键词,然后再下面的链接中在加上就行了
kyzy_yy_pm 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 kyzy_yy_pm 的回复:]
引用 3 楼 kyzy_yy_pm 的回复:
帮你顶顶
在帮你顶
[/Quote]嘿嘿
kyzy_yy_pm 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kyzy_yy_pm 的回复:]
帮你顶顶
[/Quote]在帮你顶
xuzuning 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 xinshou_php 的回复:]
我这段加什么查询条件啊,这段又不是翻页

PHP code
<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"
……
[/Quote]
$sel = "SELECT * FROM hotel_rizhi $where1 order by ".$field." ".$order." limit $start,$rowsPerPage";
你是不翻页,但是sql指令中的 $where1 $start $rowsPerPage 如何取值?
xinshou_php 2010-08-26
  • 打赏
  • 举报
回复
$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>"."  ";
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 " "." ";
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 ""."   <a href='?rizhiziduan={$rizhiziduan}&txt_ss=".rawurlencode($txt_ss)."&curPage=$maxPage' style='color:#FF0000'>尾页</a>"."   ".""
?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧