Sort menu by ID

0

I have a manageable menu, where you need to organize the items by ID. Each menu item corresponds to an ID.

$rsm = exesql('SELECT * FROM produtos_categorias WHERE id_pai = 0 AND ativo = "S" ORDER BY categoria ASC')

This is the organization I own. He is organizing by category. How would I organize by ID where I can select the specific IDs?

I tried ORDER BY ID[1,2,4,8] and it did not work.

    
asked by anonymous 01.06.2018 / 04:07

1 answer

0

Sorting logic is different from selection logic. If you need to sort by id , then just ORDER BY id [DESC] - where DESC is optional, present only when you want to sort in a decreasing way. Already, if you need to select only some of the ids, you should do this in where . I think your query should look like this:

SELECT * 
FROM produtos_categorias 
WHERE id_pai = 0 
AND ativo = "S" 
AND id IN (1,2,4,8)
ORDER BY id ASC
    
01.06.2018 / 14:57