ValhallaSkies
ValhallaSkies

Reputation: 61

PHP MySQL GROUP_CONCAT add double quotes

Can't seem to get double quotes around my results. What am I missing?

$query = "SELECT sku, GROUP_CONCAT(CONCAT('""', price, '""')) as prices FROM my_table GROUP BY sku"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
    echo $row['prices']; 
}

Comes back as a blank page. Without the CONCAT it works with comma sep.

Upvotes: 0

Views: 2327

Answers (1)

Dimi
Dimi

Reputation: 1267

Your code does not work because your string is not formatted right. You need to escape double quotes on php side so it does not treat double quotes as end of your string. modify your query to this and it should work

$query = "SELECT sku, GROUP_CONCAT(CONCAT('\"', price, '\"')) as prices FROM my_table GROUP BY sku"; 

Upvotes: 1

Related Questions