dtwxmn8741 2012-06-16 10:34
浏览 22

添加第二个php sql查询来从两个不同的表中排序结果

I've searched over the internet but since i'm beginner with php i ve countered some problems. I have a script that orders some gameserver characters by level and points. Ordering by level was easy.

The database is : cDtb
Table name which contains Level field is Character.

Now, i would like to use a second query in the same script that will order after Points field and the table name is called Reward. I have tried to add as second query like the first one but it's not showing any result.

The end result should sort by decreasing values and using the results from the two tables Character and Reward, starting with Points and then Level

Saying ... usernames Test1 and Tes2 got same level 100 but Test1 got 30Points and Test2 35Points which in this case, the rank will be Test2, Test1

Can someone help me on how to add the second query and how it should look like to order both by points and level?

Thanks in advance, below is the script

    <tr>
    <td><div align="center">Level</div></td>
    <td><div align="center">Points</div></td>
    </tr>

    <tr>                    

    <?
    $query=mssql_query("select TOP 15 * from cDtb.dbo.Character order by Level desc");
//---------- second query ??? --------------
    while($row=mssql_fetch_assoc($query)){
    $levelz=$row['Level'];
    $pointz=$row['Points'];


    ?>


    <td style="color: rgb(196, 37, 0); font-weight: bold;">
    <div align="center">
    <td><?=$levelz;?></td>
    <td><?=$pointz;?></td> 
    </div></td>

    </tr>
  • 写回答

1条回答 默认 最新

  • dpndp64206 2012-06-16 10:56
    关注

    You can order by a second field in the same result set like this:

    select TOP 15 * from cDtb.dbo.Character order by Level desc, Points desc;
    

    Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教