tags:

views:

40

answers:

0

I've built the following query programatically, but I have confirmed the query as being what is sent through the MySQLi query function.

SELECT * FROM `movie_cast` 
  JOIN `movie_x_movie_cast` ON 
    `movie_id` = "7" AND `movie_role_id` = "2" AND `movie_cast`.`id` = `movie_x_movie_cast`.`movie_cast_id` 
  ORDER BY `surname` DESC

The problem I'm hitting up on is that when I run this query in MySQL command line, I get the output listed in the order expected (by cast member's surname).

However, the result set in the PHP script is ordered by the cast member's id.

Here is the code I'm using to check the result set (I'm inside a method of a class which extends the original MySQLi library - the query method of MySQLi is NOT overridden):

$result = $this->query($query);
if ($result && $result->num_rows > 0) {
  $data = array();
  echo "<pre>";
  var_dump($query);

  while ($row = $result->fetch_assoc()) {
    var_dump($row); // this output actually shows that the result set is ordered by ID not surname
    $data[] = $row;
  }
  var_dump($data);
  echo "</pre><hr />";
}

In over 6 years of PHP, and 3 years or so of using the MySQLi I've never seen this behaviour before.

I'm using the latest PHP (5.2.10) and MySQL (5.1.37) packages on Ubuntu 9.10