Page 1 of 1

ORDER BY is returning too many results

Posted: Sat Apr 05, 2008 2:34 am
by Jarrod
This has been driving me nuts. I'm fairly new to PHP so if I'm doing this completely wrong let me know.

Whenever I query a SQLite database using an order by clause the returned array seems to combine the database columns. The first column contains the contents of each column, the second column contains the contents of each column except the first, the third column contain the contents of each column except the first and second, and so on.

Example database:

Code: Select all

Model     Make     Country
Cayman    Porsche  Germany
Elise     Lotus    England
Then the query:

Code: Select all

$db = new SQLiteDatabase("example.sdb");
$result_array = $db->arrayQuery("SELECT * FROM cars ORDER BY model LIMIT 1",SQLITE_ASSOC);
print_r($result_array); 
Returns:
Array ( [0] => Array ( [model] => CaymanPorscheGermany [make] => PorscheGermany [country] => Germany ) )

If I leave out the order by clause it works fine:
Array ( [0] => Array ( [model] => Cayman [make] => Porsche [country] => Germany ) )

What am I missing here?

Thanks in advance.

Re: ORDER BY is returning too many results

Posted: Tue May 06, 2008 3:24 pm
by califdon
I think you're missing the concept of SQL syntax. The ORDER BY clause has nothing to do with what data is returned, only in what order it will be displayed. The LIMIT clause limits the number of records included. What are you trying to do? I couldn't follow your description of your data at all.

Re: ORDER BY is returning too many results

Posted: Thu May 15, 2008 9:42 am
by chaos
I don't think you're missing anything; I think your database engine and/or the interface to it is broken.