duanpi5733 2015-07-18 11:14
浏览 36
已采纳

使用PHP查询MySQL的DESC关键字问题[重复]

This question already has an answer here:

I have a simple query ending like this...

group by subject
order by count_entries DESC, person ASC 
LIMIT 0,10

It's not at all taxing (runs immediately/correctly when I run it directly in my MySQL database using Sequel Pro).

But when run via a PHP file it returns a 500 error. All I have to do to remove the 500 error is kill the reference to DESC (either remove completely or replace with ASC) - at which point I get my results from the DB.

I really need the results sorted in descending order though, and am completely out of ideas on this really bizarre problem.

Has anyone ever seen similar behaviour with the DESC keyword?! Does anyone have any ideas at all about what I could try to fix it?!

Thanks for any thoughts.

EDIT - full code as requested...

<?php
$dbhost = 'myIP'; 
$dbuser = 'myUser'; 
$dbpass = 'myPassword'; 
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('error connecting to your database'); 
$dbname = 'myDBName'; 
mysql_select_db($dbname); // connects to your database
$myquery = "select s.subject_id
, count(e.entry_id) count_entries
, e.person
from subjects s, entries e
where s.subject_id = e.subject_id
group by s.subject_id 
order by count_entries DESC, e.person ASC
LIMIT 0,10";

$query = mysql_query($myquery);

    if ( ! $myquery ) {
        echo mysql_error();
        die;
    }
    $data = array();

    for ($x = 0; $x < mysql_num_rows($query); $x++) {
        $data[] = mysql_fetch_assoc($query);
    }

    echo json_encode($data, JSON_PRETTY_PRINT);  
    mysql_close($conn);
?>
</div>
  • 写回答

1条回答 默认 最新

  • douchuanchai2793 2015-07-18 11:39
    关注

    Put the following at the beginning of your code for the error to be displayed instead of the vague 500 error.

    ini_set('display_errors', 1);
    

    (Taken from: 500 Internal Server Error for php file not for html)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据