S
S
sashavol2015-11-01 23:48:27
MySQL
sashavol, 2015-11-01 23:48:27

Sorting by field in MySQL?

Hello.
Not strong in Mysql
I want to sort the product when displaying by a specific field. It was like this:

"SELECT * FROM `orders` WHERE `user_id`='".$_SESSION["user"]["id"]."'"

Here we display everything at once, but I need a field in this table, after searching the Internet it turned out like this:
"SELECT * FROM `orders` WHERE `user_id`='".$_SESSION["user"]["id"]."' IN (status) ORDER BY FIELD(status,'Активен')"

It doesn't work), I tried it differently but it doesn't output anything, it seems that judging by the instructions everything is correct, maybe it's in quotes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abdula Magomedov, 2015-11-01
@sashavol

"SELECT * FROM `orders` WHERE `user_id`='" . $_SESSION["user"]["id"] . "' AND `status` = 'Активен'"

M
Max, 2015-11-02
@MaxDukov

Do you need sorting or filtering?

SELECT * FROM `orders` WHERE `user_id`='" . $_SESSION["user"]["id"] . "' and 'status' = 'Активен'
is a filter. It will show all the lines in which status = Active and user_id = $_SESSION["user"]["id"]
judging by the abundance of quotes - are you collecting the query in PHP? Does your language match?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question