0

I'm having difficulties with SQLite3. The table is as follow:

id|name
11|test1
31|test1
51|test1
13|test2
17|test2
..|..

I need to get only one name and all id's for that name, like this:

test1|array(11,31,51)
test2|array(13,17)
...

How can I do it with PHP and SQLite3? Thank you.

4

1 回答 1

2

使用 group_concat

SELECT 
    name,
    group_concat(id) AS ids
FROM Table
GROUP BY name

会返回类似的东西

test1|11,31,51
test2|13,17

然后你可以爆炸 ids,把它们作为数组。

$ids_array = explode(",",$ids);
于 2013-07-01T14:36:15.257 回答