JRsz JRsz - 5 months ago 16
PHP Question

PHP: Get mysql result of multiple rows in one with group_concat

I have a table which has a clumn

id
and a column
isadmin
.

I want to execute this query, which works just fine:

$query = "SELECT id FROM mytable WHERE isadmin = TRUE;";


But instead of getting multiple rows I would like to get one row in csv format.
I found this link and created the following query, which does not work, I get a mysql error:

$query = "SELECT GROUP_CONCAT(id SEPERATOR ',') FROM mytable WHERE isadmin = TRUE;";


The error message is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SEPERATOR ', ') FROM mytable WHERE isadmin = TRUE' at line 1


If this is not enough information just tell me and I will provide them.

Answer

The comma is the defaul separator so you don't need

 SELECT GROUP_CONCAT(id ) FROM mytable WHERE isadmin = TRUE;

anyway is separator and nt seperator

SELECT GROUP_CONCAT(id SEPARATOR ',') FROM mytable WHERE isadmin = TRUE;