dsfsfsfsfs55656 2014-09-30 06:53
浏览 32

PHP多维数组排序

Edit : I need it to do only in Array Sort, As i am using procedure and sending it into json,

Here is my Table Structure,

SQL Fiddle

enter image description here

I want to display as

  1. alpha london
  2. alpha newyork
  3. beta delhi
  4. beta sydney

I mean, the second coloumn (name) should be in Ascending Order and the third coloumn (place) should be in Descending Order.

How i want is

  1. alpha london
  2. alpha newyowk
  3. beta delhi
  4. beta sydney

The Name should be in Asc Order and then to the right, the Place should be in Desc Order

What i have tried so far is

How can i do this ??

<?php
include ('conn.php');
$sql="SELECT * FROM test";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
while($rows=mysql_fetch_array($result))
{
foreach($result as $k=>$v)
{
echo $k;

}
}
?>

It displays the result as Invalid argument supplied to for each. What is the mistake i am doing and how can achieve my output

  • 写回答

5条回答 默认 最新

  • dongyan1936 2014-09-30 06:55
    关注

    So why don't you do an order in your query itself like

    SELECT * FROM test order by name;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起