trying to put an mysql result into a string
Posted
by
user1583432
on Stack Overflow
See other posts from Stack Overflow
or by user1583432
Published on 2012-09-13T21:35:53Z
Indexed on
2012/09/13
21:37 UTC
Read the original article
Hit count: 198
I'm trying to put an mysql query result into an string I tried to find an answer but all the similar posts were getting subquery answers which is not what I'm trying to do.
for example
Fruits_tbl ID Fruit Color Number __________________________________ 2 Apple Red 5
$sql = "select Fruits,Color,Number from Fruits_tbl where ID = 2";
$result = $pdo->query($sql);
$row = $result->fetch();
print_r($row);
This will give me something like
Array([0]=>"Apple", [1]=>"Red", [2]=>"5", [Fruit]=>"Apple", [Color]=>"Red", [Number]=>"5")
implode will give me 2 of each
I want just need a string = "Apple, Red, 5"
what I currently have is
$string = $row[Fruit].", ".$row[Color].", ".$row['Number']
As you can see that's rather tedious.
Is there something like implode but only return the index array or something?
© Stack Overflow or respective owner