ORDER BY is returning too many results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jarrod
Forum Newbie
Posts: 1
Joined: Sat Apr 05, 2008 2:09 am

ORDER BY is returning too many results

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: ORDER BY is returning too many results

Post 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.
User avatar
chaos
Forum Newbie
Posts: 22
Joined: Thu May 15, 2008 9:20 am
Location: New Jersey

Re: ORDER BY is returning too many results

Post by chaos »

I don't think you're missing anything; I think your database engine and/or the interface to it is broken.
Post Reply