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)

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

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答