I am pretty new to PHP and am trying to do something that i cannot find specific definition for anywhere. It goes like this:
I have variables from a form... alot of them.
They correspond to editable fields of a MySQL sourced table displayed on the previous page.
I am trying to compare these form submitted variables to the original table data which i load into an array.
I am trying to get these submitted variables into a a matching multidimensional array for easy comparison (need to determine the differences of each field).
Now the submitted variables have a naming scheme which will lend itself to my endeavor.
i am trying to fill a two-dimensional array,via a for loop, one "row" at a time with the variables. However i need to specify the names of the variables for each "row" using the iteration counter of my loop. But it does not seem to be working. Sorry if i am not explaining this well... perhaps the code will help explain better.
Code: Select all
for ( $i=0; $i<$eNumRecords; $i++)
{
$Wines = "Wines_".$i;
$CostPerBottle = "CostPerBottle_".$i;
$OnHand = "OnHand".$i;
$Sold = "Sold".$i;
$Price = "Price".$i;
$Shipping_2 = "Shipping_2".$i;
$Shipper_2 = "Shipper_2".$i;
$Pay_Pal = "Pay_Pal".$i;
$Sales_Tax = "Sales_Tax".$i;
$PalPay = "PalPay".$i;
$Count = "Count".$i;
$Expense = "Expense".$i;
$WC_Comm = "WC_Comm".$i;
$Modified .= array( array( Wines => $$Wines,
CostPerBottle => $$CostPerBottle,
OnHand => $$OnHand,
Sold => $$Sold,
Price => $$Price,
Shipping_2 => $$Shipping_2,
Shipper_2 => $$Shipper_2,
PayPal => $$Pay_Pal,
Sales_Tax => $$Sales_Tax,
PalPay => $$PalPay,
Count => $$Count,
Expense => $$Expense,
WC_Comm => $$WC_Comm
));
}
echo $Modifiedї0]ї"Price"];Now... that last echo command should (in my mind) print out the value of the variable which came in via the form as $Wines_0
Placing
Code: Select all
echo $Wines_0;This would not be such a big deal if the number of rows was static but it is not so getting over this hump is essential to my design.
Do I not have a correct understanding of $$varname's or perhaps My Array is not being built properly ( .= )???
Any light you guys could shed would be most helpful.
For better or for worse even.. just so i know.
It seems to me this is just the kind of thing that $$varname's would be used for.
But again... I'm new to this.
Thanx!
John
(In case you are wondering why I would do such a thing I am porting an excel spreadsheet to PHP sourcing MySQL)