Sort menu by ID

Asked

Viewed 53 times

0

I have a manageable menu, where you will need to organize 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. It’s organizing by category. How I would organize by ID, where I can select specific Ids?

I tried to ORDER BY ID[1,2,4,8] and it didn’t work.

1 answer

0

Sorting logic is different from selection logic. If you need to sort by id, then just do ORDER BY id [DESC] - where DESC is optional, present only when you wish to sort in a decreasing way. Already, if you need to select only a few of the ids, you should do this in the where. I believe your consultation 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.