Page 1 of 1

[SOLVED] Walking Through a Multi-Demnsional PHP Array

Posted: Mon Aug 03, 2009 12:53 pm
by shaiss
I can't figure out why this snippet of code isn't working :banghead: any ideas?

Code: Select all

       
$productref = $order_detail[$i][2]; //#2 is the product ID
        $orderqty = $order_detail[$i][3];   //#3 is the SKU #
The Array:

Code: Select all

 
$order_detail array
    0                 array
        id_order_detail    string  = 1
        product_id         string  = 7
        product_qtantity string = 1
        reference           string = 1021400
 
This array is the result of a mysql query.
Any help is appriciated. Thank you!!!!!


Here is the entire function if needed

Code: Select all

function BuildQueryString($order_id, $order_detail)
{
    $num = sizeof($order_detail);
    $i=0;
    $count=1;
    $baseURL = "OrderNumber=$order_id";
    while ($i < $num)
    {
        $productref = $order_detail[$i][2]; //#2 is the product ID
        $orderqty = $order_detail[$i][3];   //#3 is the SKU #
        
        /*$productref = "&SKU0$count=$productref&";
        $orderqty = "Qty0$count=$orderqty";*/
        
        $sku = "&SKU0$count=$productref&";
        $qty = "Qty0$count=$orderqty";
        
        $prodURL = $prodURL . $sku . $qty;
        
        $i++;
        $count++;
    }    
    return $baseURL . $prodURL;
}

Re: Walking Through a Multi-Demnsional PHP Array

Posted: Mon Aug 03, 2009 1:17 pm
by shaiss
Because I used mysql associative array this is the correct code:

Code: Select all

 
<?php
$productref = $order_detail[$i]['product_id']; // is the product ID
$orderqty = $order_detail[$i]['product_quantity'];   // is the SKU #