I can't figure out why this snippet of code isn't working :facewall: any ideas?

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

The Array:

$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

function BuildQueryString($order_id, $order_detail)
    $num = sizeof($order_detail);
    $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;
    return $baseURL . $prodURL;


The function will simplify to this:

function BuildQueryString($orderNumber, $order_detail){
    $prodURL = array("OrderNumber=$orderNumber");
    for($i=0; $i<count($order_detail); $i++){
        $prodURL[] = "SKU" . ($i+1) . "=" . $order_detail[$i][2];
        $prodURL[] = "Qty" . ($i+1) . "=" . $order_detail[$i][3];
    return implode('&', $prodURL);

I've not tested but this should work within itself. It's overall effectiveness at achieving what you want depends on the parameters you pass in.


Airshow, thank you for the reply!
I figured that I need to reference the column by name not by index since the results coming from mysql.

Thanks for the simplification, I'll work on implementing that in.


That should be trivial. I guess you just replace [2] and [3] with the column names, eg. and (or similar).

However, I have just thought ...... if the data is in a database then a better strategy might be to extract it from the database in the target page rather than pass it in the query string. That would certainly be more normal and would give you the data in array form such that you could loop through it for whatever purpose.