catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

[BUG?] Problem with ORDER BY with WHERE with v1.1.3 #476

Closed ghost closed 8 years ago

ghost commented 8 years ago

hi, i'm trying to make a query with Where & Order and it's seems to not work. i'm using the log() to see the build query. Is anyone have the same problem that me or is it a bug ? (i know that i could use the query() but i want to pass thru the normal way ) :

i want to make : SELECT id WHERE id>=10 ORDER BY car_id ASC

$database->select("account",
    "id",
    ["ORDER" => ["carId" => "ASC"]],
    ["id[>=]"=>10]
);

return me -> SELECT "id" FROM "account" ORDER BY "carId" ASC

$database->select("account",
    "id",
    ["id[>=]"=>10],
    ["ORDER" => ["carId" => "ASC"]]
);

return me -> SELECT "id" FROM "account" WHERE "id" >= 10

$database->select("account",
    "id",
    [["id[>=]"=>10], "ORDER" => ["carId" => "ASC"]]
);

return me -> SELECT "id" FROM "account" WHERE "0" IN (10) ORDER BY "carId" ASC

$database->select("account",
    "id",
    ["ORDER" => ["carId" => "ASC"]],
    ["id[>=]"=>10]
);

return me -> SELECT "id" FROM "account" ORDER BY "carId" ASC

thank ! Great library, i'm using it more and more for my project !!!

ghost commented 8 years ago

I finally found my error when making another query... the correct syntax is, per example :

$articles = $database->select("articles",
    ["id","title","titleSanityzed","content","dateOnline"],
    [
        "id[!]" => $whereExclude["id"],
        "ORDER" => ["dateOnline"=> "DESC"],
        "LIMIT" => $limit
    ]
);

result -> SELECT "id","title","titleSanityzed","content","dateOnline" FROM "articles" WHERE "id" != '1' ORDER BY "dateOnline" DESC LIMIT 2

for thoses who struggle with the medoo syntax... Works like a charm!