Retrieve part of a MySQL column with PHP

Posted by Gerardo Marset on Stack Overflow See other posts from Stack Overflow or by Gerardo Marset
Published on 2010-05-24T19:31:19Z Indexed on 2010/05/24 19:41 UTC
Read the original article Hit count: 264

Filed under:
|

For instance, if I have the following table:

+----+---+----------+
| id | a | position |
+----+---+----------+
| 0  | 0 | 0        |
| 1  | 0 | 1        |
| 2  | 1 | 4        |
| 3  | 1 | 9        |
| 4  | 1 | 6        |
| 5  | 1 | 1        |
+----+---+----------+

and I want to get an array that contains the first 100 values from position where a is 1 in ascending order, what would I do?
Im guessing something like this:

$col = mysql_fetch_array( mysql_query('
SELECT `position`
FROM `table`
WHERE `a`="1"
ORDER BY `position` ASC
LIMIT 100
'));

I'd expect to get the following array:

+-------+-------+
| index | value |
+-------+-------+
| 0     | 1     |
| 1     | 4     |
| 2     | 6     |
| 3     | 9     |
+-------+-------+

but it doesn't work.
¿What should I do to make it work?
Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql