首页 新闻 会员 周边 捐助

php 基础问题表单里面怎么升序和降序?

0
悬赏园豆:20 [已解决问题] 解决于 2017-05-05 12:51

<?php
require_once 'conn.php';

//1.查询总记录数
require_Once "DbHelper.class.php";

$arr=array("host"=>"localhost","uid"=>"root","pwd"=>"","dbname"=>"aaa","charset"=>"utf8");

$db=new DbHelper($arr);

$recordcount=$db->getRecordCount("select count(*) from user");

//2.设置每页大小
$perpage=5;

if(isset($_GET['jieshou'])){

$perpage=$_GET['jieshou'];
}

//3.创建分页类对象
require_once "Pager.class.php";

$pager=new Pager(array("total"=>$recordcount,"perpage"=>$perpage));

if (isset($_GET['key'])) {
$key = $_GET['key'];
$sql="select * from user where (uname like '%$key%') or (contacts like '%$key%') or (tele like '%$key%') or
(mobile_phone like '%$key%') or (qq like '%$key%') or (email like '%$key%') or (url like '%$key%') or
(remarks like '%$key%') order by id asc limit $pager->offset,$perpage";
} else{
$sql="select * from user order by id asc limit $pager->offset,$perpage ";
}

$arr=$db->execDql($sql);

echo " <table border='1' > " ;

$peopie=array("id"=>"id","uname"=>"uname","contacts"=>"contacts","tele"=>"tele",
"mobile_phone"=>"mobile_phone","qq"=>"qq","email"=>"email","url"=>"url","remarks"=>"remarks");

foreach ( $peopie as $mychars )

sort($peopie);
rsort($peopie);

echo "<tr><td>id</td> <td>客户名</td> <td>联系人</td> <td>电话</td> <td>手机</td> <td>QQ</td>
<td>邮箱</td> <td>地址</td> <td>备注</td> </tr> ";

foreach ($arr as $row ) {

?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['uname'];?></td>
<td><?php echo $row['contacts'];?></td>
<td><?php echo $row['tele'];?></td>
<td><?php echo $row['mobile_phone'];?></td>
<td><?php echo $row['qq'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['url'];?></td>
<td><?php echo $row['remarks'];?></td>

<td><a href='javascript:if(confirm("确认删除"))
location.href="shanchu.php?id=<?php echo $row['id'];?>&jieshou=<?php echo $perpage;?>"'>删除</a></td>

<td><a href="xiugai.php?id=<?php echo $row['id'];?>&jieshou=<?php echo $perpage;?>">修改</a></td>
</tr>
<?php
}
sort($peopie);
echo "</table>";

?>

 

标记地方改怎么改?

 

灰色的蓝的主页 灰色的蓝 | 初学一级 | 园豆:176
提问于:2017-05-05 09:53
< >
分享
最佳答案
0

所谓的升序降序应该都是针对sql语句,php只是读出数据库信息,然后显示在页面,如果查找内容时需要选择升序还是降序显示,只需要改变点击的url参数就可以,例如URL参数是?sort=desc,php就可以用$sort= $_GET['sort'];接收到参数放入sql(select * form table_name order by age $sort),这里就是根据age的降序排列,升序只需改变传递的参数就行

收获园豆:20
风行天下12 | 老鸟四级 |园豆:3867 | 2017-05-05 10:31

能不能帮忙改下代码?新人一个,需要实际案例(源码)。

灰色的蓝 | 园豆:176 (初学一级) | 2017-05-05 10:34

@灰色的蓝: 你要实现什么样的效果,可不可以给一个展示的效果图

风行天下12 | 园豆:3867 (老鸟四级) | 2017-05-05 10:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册