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);
?>