0

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.

2
  • $order_number .= $d[0][1]; - try with this Commented Jun 16, 2013 at 7:47
  • you have to initialize $order_number first. Place $order_number = ""; before the foreach. Commented Jun 16, 2013 at 7:51

1 Answer 1

1

Replace this...

 `foreach($row as $d){

with this....

$order_number = "";   
 foreach($row as $val){
    $order_number.= ",".$val[1];
 }
echo $order_number;
Sign up to request clarification or add additional context in comments.

1 Comment

Are you sure thats your structure when outputting $row....can you echo "<pre>" before you print_r, so we can see it more visually than on one line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.