'Put all rows from 1 column in 1 varchar
I have 1 table (in MySQL) with 1 row. The values of that table are for example:
5
24
67
I select the values with this query:
$oudeGetallen = $conn->query("SELECT getal from ingezettegetallen");
Now I would like to put the values of that table in 1 text variable in PHP.
So that $oudeGetallenString = 52467
I cannot manage that. I tried putting it in an array and use implode after that, but that didn't work. Could you please help me?
Solution 1:[1]
It is strange to concatenate numeric vales like that, but you can do it with the use of GROUP_CONCAT() aggregate function if you specify the empty string '' as the separator:
SELECT GROUP_CONCAT(getal SEPARATOR '') AS col
FROM ingezettegetallen;
or with an ORDER BY clause:
SELECT GROUP_CONCAT(getal ORDER BY getal SEPARATOR '') AS col
FROM ingezettegetallen;
See the demo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | forpas |
