Jump to content

Recommended Posts

Hey,

 

I am trying to use a variable in an array key with no success.

 

here is a snippet of code:

 

$row_i = 1;
foreach($enrolled_array as $enrolled_client){
$cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_".$row_i."[0]";
$fields[$cell_1]->setValue($enrolled_client['clientid']);
$row_i++;
}

 

I get the following error:

 

[19-Mar-2009 08:20:50] PHP Fatal error:  Call to a member function setValue() on a non-object in /home/prime09/public_html/autoforms/broker_invoice.php on line 139

 

If I manually put in the following it will work without any issues but of course what I am trying to do here is have the array key change each time the loop passes through.

 

Works:

$fields['topmostSubform[0].Page1[0].SMART_ID___Row_1[0]']->setValue($enrolled_client['clientid']);

 

 

Any tips appreciated! I am sure its something obvious.

Link to comment
https://forums.phpfreaks.com/topic/150059-variable-in-array-key/
Share on other sites

ok, but

 

$fields['topmostSubform[0].Page1[0].SMART_ID___Row_1[0]']

 

is an object and $cell_1 is equal to topmostSubform[0].Page1[0].SMART_ID___Row_1[0].

 

So why does $fields[$cell_1] not work? How can I overcome this?

 

Thanks.

 

 

 

Also the following works fine: ($row_i is replace with "1")

 

$row_i = 1;
foreach($enrolled_array as $enrolled_client){
$cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_1[0]";
$fields[$cell_1]->setValue($enrolled_client['clientid']);
$row_i++;
}

$row_i = 1;
foreach($enrolled_array as $enrolled_client){
echo $cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_1[0]";
             echo "<br/>";
             echo $cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_".$row_i."[0]";

$fields[$cell_1]->setValue($enrolled_client['clientid']);
$row_i++;
}

 

 

check closely if they are exactly same.

$row_i = 1;
foreach($enrolled_array as $enrolled_client){
echo $cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_1[0]";
            echo "<br/>";
            echo $cell_1 = "topmostSubform[0].Page1[0].SMART_ID___Row_".$row_i."[0]";
             echo "<br/>";

$fields[$cell_1]->setValue($enrolled_client['clientid']);
$row_i++;
}

 

 

check closely if they are exactly same.

 

They look exactly the same. Is this a bug in PHP?

 

Output:

topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_2[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_3[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_4[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_5[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_6[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_7[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_8[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_9[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_10[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_11[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_12[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_13[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_14[0]
topmostSubform[0].Page1[0].SMART_ID___Row_1[0]
topmostSubform[0].Page1[0].SMART_ID___Row_15[0]

tray to

print_r(array_keys($fields));

and look which one miss

 

Output:

 

Array

(

    [0] => topmostSubform[0].Page1[0].ica_name[0]

    [1] => topmostSubform[0].Page1[0].ica_bank[0]

    [2] => topmostSubform[0].Page1[0].ica_bsb[0]

    [3] => topmostSubform[0].Page1[0].ica_account_no[0]

    [4] => topmostSubform[0].Page1[0].SMART_ID___Row_1[0]

    [5] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_1[0]

    [6] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_1[0]

    [7] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_1[0]

    [8] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_1[0]

    [9] => topmostSubform[0].Page1[0].TOTAL__Row_1[0]

    [10] => topmostSubform[0].Page1[0].SMART_ID___Row_2[0]

    [11] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_2[0]

    [12] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_2[0]

    [13] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_2[0]

    [14] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_2[0]

    [15] => topmostSubform[0].Page1[0].TOTAL__Row_2[0]

    [16] => topmostSubform[0].Page1[0].SMART_ID___Row_3[0]

    [17] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_3[0]

    [18] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_3[0]

    [19] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_3[0]

    [20] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_3[0]

    [21] => topmostSubform[0].Page1[0].TOTAL__Row_3[0]

    [22] => topmostSubform[0].Page1[0].SMART_ID___Row_4[0]

    [23] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_4[0]

    [24] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_4[0]

    [25] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_4[0]

    [26] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_4[0]

    [27] => topmostSubform[0].Page1[0].TOTAL__Row_4[0]

    [28] => topmostSubform[0].Page1[0].SMART_ID___Row_5[0]

    [29] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_5[0]

    [30] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_5[0]

    [31] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_5[0]

    [32] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_5[0]

    [33] => topmostSubform[0].Page1[0].TOTAL__Row_5[0]

    [34] => topmostSubform[0].Page1[0].SMART_ID___Row_6[0]

    [35] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_6[0]

    [36] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_6[0]

    [37] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_6[0]

    [38] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_6[0]

    [39] => topmostSubform[0].Page1[0].TOTAL__Row_6[0]

    [40] => topmostSubform[0].Page1[0].SMART_ID___Row_7[0]

    [41] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_7[0]

    [42] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_7[0]

    [43] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_7[0]

    [44] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_7[0]

    [45] => topmostSubform[0].Page1[0].TOTAL__Row_7[0]

    [46] => topmostSubform[0].Page1[0].SMART_ID___Row_8[0]

    [47] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_8[0]

    [48] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_8[0]

    [49] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_8[0]

    [50] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_8[0]

    [51] => topmostSubform[0].Page1[0].TOTAL__Row_8[0]

    [52] => topmostSubform[0].Page1[0].SMART_ID___Row_9[0]

    [53] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_9[0]

    [54] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_9[0]

    [55] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_9[0]

    [56] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_9[0]

    [57] => topmostSubform[0].Page1[0].TOTAL__Row_9[0]

    [58] => topmostSubform[0].Page1[0].SMART_ID___Row_10[0]

    [59] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_10[0]

    [60] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_10[0]

    [61] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_10[0]

    [62] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_10[0]

    [63] => topmostSubform[0].Page1[0].TOTAL__Row_10[0]

    [64] => topmostSubform[0].Page1[0].SMART_ID___Row_11[0]

    [65] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_11[0]

    [66] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_11[0]

    [67] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_11[0]

    [68] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_11[0]

    [69] => topmostSubform[0].Page1[0].TOTAL__Row_11[0]

    [70] => topmostSubform[0].Page1[0].SMART_ID___Row_12[0]

    [71] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_12[0]

    [72] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_12[0]

    [73] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_12[0]

    [74] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_12[0]

    [75] => topmostSubform[0].Page1[0].TOTAL__Row_12[0]

    [76] => topmostSubform[0].Page1[0].SMART_ID___Row_13[0]

    [77] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_13[0]

    [78] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_13[0]

    [79] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_13[0]

    [80] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_13[0]

    [81] => topmostSubform[0].Page1[0].TOTAL__Row_13[0]

    [82] => topmostSubform[0].Page1[0].SMART_ID___Row_14[0]

    [83] => topmostSubform[0].Page1[0].CLIENT_NAME__Row_14[0]

    [84] => topmostSubform[0].Page1[0].BUSINESS_NAME__Row_14[0]

    [85] => topmostSubform[0].Page1[0].INITIAL_PAYMENT__Row_14[0]

    [86] => topmostSubform[0].Page1[0].TRAILING_FEE__Row_14[0]

    [87] => topmostSubform[0].Page1[0].TOTAL__Row_14[0]

    [88] => topmostSubform[0].Page1[0].subtotal[0]

    [89] => topmostSubform[0].Page1[0].gst[0]

    [90] => topmostSubform[0].Page1[0].total_due[0]

    [91] => topmostSubform[0].Page1[0].ica_name[1]

    [92] => topmostSubform[0].Page1[0].ica_address[0]

    [93] => topmostSubform[0].Page1[0].ica_phone[0]

    [94] => topmostSubform[0].Page1[0].comments[0]

    [95] => topmostSubform[0].Page1[0].invoice_number[0]

    [96] => topmostSubform[0].Page1[0].invoice_date[0]

    [97] => topmostSubform[0].Page1[0].date_range[0]

)

 

 

 

I still can't solve this problem. It seems like what i have done SHOULD work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.