Reputation: 294
Im pretty new to MySQl and PHP. I need some help with a small issue.
My statement is as follows:
while($row = $stmt->fetch()) {
$return_arr[] = $row['name'];
$return_arr[] = $row['value'];
}
It outputs as follows:
Mr James Jones
23
How can I bring it together into one line? Like this:
Mr James Jones 23
Thank you
Upvotes: 0
Views: 120
Reputation: 68556
Do like this
while($row = $stmt->fetch()) {
$return_arr[] = $row['name']." ".$row['value'];
}
//print_r($return_arr); // The results gets printed as you expected or you could make use of a foreach construct as shown below.
//Printing using a foreach construct
foreach($return_arr as $k=>$v)
{
echo $v;echo "<br>";
}
Upvotes: 3
Reputation: 213
An alternate way is handling it inside your mysql query:
SELECT CONCAT(name, ' ', value) as name_and_value FROM ....
Than you can use
$row['name_and_value']
in your php code.
Upvotes: 0
Reputation: 720
Just use like this,
while($row = $stmt->fetch()) {
$return_arr[] = $row['name']. ' '.$row['value'];
}
it will work. And if you want any other help let me know.
Upvotes: 0