Jibon
Jibon

Reputation: 342

Create string from multi-dimensional array values

I have a code like this:

$user = JFactory::getUser();
$user_id= $user->get('id');

$db = JFactory::getDbo();
$db->setQuery("SELECT virtuemart_user_id, order_number, order_total, created_on FROM `kunkp_virtuemart_orders` WHERE `virtuemart_user_id`='$user_id' ");

$row = $db->loadRowList();

print_r($row);`

The output of the result is like this:


Array
(
    [0] => Array
        (
            [0] => 42
            [1] => 10e803
            [2] => 122.05487
            [3] => 2013-06-10 20:34:39
        )

    [1] => Array
    (
        [0] => 42
        [1] => 901e04
        [2] => 349.78500
        [3] => 2013-06-11 07:28:19
    )

)

Here, 10e803 & 901e04 is order number. I want to store all the order number in `$order_number` string & want to print the value of `$order_number` . How I can do that. I tried with foreach like this:

`foreach($row as $d){

    $order_number .= $d[1];
}
echo $order_number;

But it's not working. Anyone can help me please.

Upvotes: 0

Views: 67

Answers (1)

Kylie
Kylie

Reputation: 11749

Replace this...

 `foreach($row as $d){

with this....

$order_number = "";   
 foreach($row as $val){
    $order_number.= ",".$val[1];
 }
echo $order_number;

Upvotes: 1

Related Questions