Mends.One

simple sql order by position

Mysqli, Php

Okay I have been putting this off because it has been partially working, now I need it.

I want this output:

id position
1       1       
2       2        
15      3         
16      4          

I thought this^ would do it. But I am getting the whole pages table.

SELECT * 
FROM pages 
ORDER BY position ASC

id  link_id     menu_name     position     content     visible
1     1         New Article       1     This is the first Picture and   Article     1
2     1         Edit Articles     2     Delete Articles/Edit 333
0
W
WackyMole
Jump to: Answer 1 Answer 2 Answer 3

Answers (3)

The * in your query means you'll select every colomn, just use the columnames you want to retrieve.

example:

SELECT id, position FROM pages ORDER BY position

That's all ;)

1
F
Frederik Voordeckers

All you need to do is specify your columns:

SELECT id, position FROM pages ORDER BY position ASC

1
D
datasage

whenever you need specific columns from the table ...you need to mention them in your SELECT clause.

In your case you need id and position only so your query will be

SELECT id, position FROM pages ORDER BY position ASC

For further learning check this link..

hope this helps you..

0
A
alwaysLearn

Related Questions