PHP查询并排序
mysql_connect('localhost','root','123456')ordie('连接数据库失败!');mysql_select_db('tydj')or...
mysql_connect('localhost','root','123456') or die('连接数据库失败!');
mysql_select_db('tydj') or die('选择数据库失败!');
mysql_query('set names utf8');
date_default_timezone_set("PRC");
$a = date("Y-m-d H:i:s");
$rowtime = strtotime($a);
$sql="select nickname from tydjadmin WHERE nickname!='' and (nickname='城关镇' or nickname='韩庄镇' or nickname='白营镇' or nickname='古贤镇' or nickname='菜园镇' or nickname='任固镇' or nickname='五陵镇' or nickname='瓦岗乡' or nickname='伏道镇' or nickname='宜沟镇')";
$result=mysql_query($sql);
$i=1;
while($rowsql=mysql_fetch_array($result)){
$sql1="SELECT *,count(*) as nub FROM tydjinfolist where author='".$rowsql['nickname']."' and delstate='' AND checkinfo=true ORDER BY nub DESC,8";
$result1=mysql_query($sql1);
while($rowsql1=mysql_fetch_array($result1)){
$sql2="SELECT *, count(*) as nua FROM tydjinfolist where author='".$rowsql['nickname']."' and delstate='' AND checkinfo=true and (posttime<='$rowtime' and (posttime>='".$rowsql1['posttime']."')) ORDER BY nua DESC,8";
$result2=mysql_query($sql2);
while($rowsql2=mysql_fetch_array($result2))
{
?>
<li><span><?php echo $i;?></span><span><?php echo $rowsql2['author'];?></span> <span><?php echo $rowsql1['nub'];?></span><span><?php echo $rowsql2['nua'];?></span></li>
<?php
}} $i=$i+1;}
?>
输出结果
1城关镇 1 1
2韩庄镇 2 2
3白营镇 2 2
4古贤镇 1 1
5 0 0
6 0 0
7 0 0
8伏道镇 1 1
9宜沟镇 3 3
10菜园镇 1 1
需要进行排序 应该怎么改? 展开
mysql_select_db('tydj') or die('选择数据库失败!');
mysql_query('set names utf8');
date_default_timezone_set("PRC");
$a = date("Y-m-d H:i:s");
$rowtime = strtotime($a);
$sql="select nickname from tydjadmin WHERE nickname!='' and (nickname='城关镇' or nickname='韩庄镇' or nickname='白营镇' or nickname='古贤镇' or nickname='菜园镇' or nickname='任固镇' or nickname='五陵镇' or nickname='瓦岗乡' or nickname='伏道镇' or nickname='宜沟镇')";
$result=mysql_query($sql);
$i=1;
while($rowsql=mysql_fetch_array($result)){
$sql1="SELECT *,count(*) as nub FROM tydjinfolist where author='".$rowsql['nickname']."' and delstate='' AND checkinfo=true ORDER BY nub DESC,8";
$result1=mysql_query($sql1);
while($rowsql1=mysql_fetch_array($result1)){
$sql2="SELECT *, count(*) as nua FROM tydjinfolist where author='".$rowsql['nickname']."' and delstate='' AND checkinfo=true and (posttime<='$rowtime' and (posttime>='".$rowsql1['posttime']."')) ORDER BY nua DESC,8";
$result2=mysql_query($sql2);
while($rowsql2=mysql_fetch_array($result2))
{
?>
<li><span><?php echo $i;?></span><span><?php echo $rowsql2['author'];?></span> <span><?php echo $rowsql1['nub'];?></span><span><?php echo $rowsql2['nua'];?></span></li>
<?php
}} $i=$i+1;}
?>
输出结果
1城关镇 1 1
2韩庄镇 2 2
3白营镇 2 2
4古贤镇 1 1
5 0 0
6 0 0
7 0 0
8伏道镇 1 1
9宜沟镇 3 3
10菜园镇 1 1
需要进行排序 应该怎么改? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询