简体   繁体   English

如何对该字母SQL查询按字母顺序排序?

[英]How do I sort in alphabetical order this SQL query?

I have tried with sort() in front of $new but it won't work, where should I put it? 我已经在$ new前面尝试过sort(),但是它不起作用,应该放在哪里?

$new = mysql_query("SHOW COLUMNS FROM Professors");

   while($row = mysql_fetch_array($new)) {  

    $output .= "{$row['Field']}";
    echo $output;
}

I have also tried something like this: 我也尝试过这样的事情:

  $new = "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE   table_name = 'Professors' ORDER BY column_name";

but, while on my SQL compiler it will sort them correctly, they won't get printed on the page with the exact code above. 但是,尽管在我的SQL编译器上可以正确地对它们进行排序,但它们不会被打印在上面的确切代码上。

Try this, then: 试试这个,然后:

 $new = "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE   table_name = 'Professors' ORDER BY column_name";

   while($row = mysql_fetch_array($new)) {  
    $output = $row['column_name'] . "<br>";
    echo $output;
}

You were ordering it correctly and selecting by column name but you weren't getting the correct field names. 您已正确排序并按列名进行选择,但未获得正确的字段名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM