jaxdevil Posted November 11, 2008 Share Posted November 11, 2008 This one is irritating me. I made a loop to count from 0 to 40, and inside the loop I have hidden from fields. The names of the fields are like model_number_1, description_1, qty_item_1, etc. The values for those are in $model_number_[0], $description_[0], $qty_item_[0], etc. I made a seperate variable that adds +1 onto the loop variable so it syncs up the _1 and the _[0] value that goes with it. The problem is, how do I get the array variables to populate into the hidden form fields? Normally I use the code just inside of the loop as below, but I guess because it is the array it does not function right, the data for the value is always either blank, or if I modify the code some I actually get it to print out $model_number_[0], $description_[0], $qty_item_[0] , the actual text just like I just typed it, it outputs to the browser verbatim as $model_number_[0], $description_[0], $qty_item_[0], it does not actually call the variable or display the variable that matches to that variable/array. If I make $model_number = $model_number_[0] it will display the correct variable data, but for whatever reason, the way the code is below, does not. Anyone have an idea why it doesn't? Or know a way I can call the array variables that match to each hidden form field WITHIN the loop statement so the same code doesn't have to be replicated by hand 40 times? Here is the code I am using: <? for ($i = 0; $i <41; $i++) { $t = $i+1; ?> <? $model_number = "model_number_[".$i."]"; $model_number = $$model_number; $description = "description_[".$i."]"; $description = $$description; $qty_item = "qty_item_[".$i."]"; $qty_item = $$qty_item; $price_item = "price_item_[".$i."]"; $price_item = $$price_item; $total_item = "total_item_[".$i."]"; $total_item = $$total_item; $po_number = "po_number_[".$i."]"; $po_number = $$po_number; ?> Model Number <?=$t?>: <?=$model_number?><br> Description <?=$t?>: <?=$description?><br> Qty Item <?=$t?>: <?=$qty_item?><br> Price Item <?=$t?>: <?=$price_item?><br> Total Item <?=$t?>: <?=$total_item?><br> PO Number <?=$t?>: <?=$po_number?><br> <input type="hidden" name="model_number_<?=$t?>" value="<?=$model_number?>"> <input type="hidden" name="description_<?=$t?>" value="<?=$$description?>"> <input type="hidden" name="qty_item_<?=$t?>" value="<?=$$qty_item?>"> <input type="hidden" name="price_item_<?=$t?>" value="<?=$$price_item?>"> <input type="hidden" name="total_item_<?=$t?>" value="<?=$$total_item?>"> <input type="hidden" name="po_number_<?=$t?>" value="<?=$$po_number?>"> <? } ?> Whats weird is on a different page I use this code, and it works for displaying the variable data, the only difference is that data is not in an array, so that has to be the reason. <? $price_item_x = "price_item_".$x; $price_item_x = $$price_item_x; ?> Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 11, 2008 Share Posted November 11, 2008 Why not simply display the relevant entry like any normal person would: <?php for ($i = 0; $i <41; $i++) { $t = $i+1; echo '<input type="hidden" name="model_number_'.$t.'" value="'.$model_number[$i].'">'; } ?> Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted November 11, 2008 Author Share Posted November 11, 2008 That works. Thanks guy, but I don't know what to say exactly. You helped me which is a nice thing, and you insulted me at the same time. Just weird I guess, usually nice people help others and are polite, and rude people insult other people and do not help them. That means you are not normal either. We can smell are own I guess. Thanks for the help anyways. SK Quote Link to comment Share on other sites More sharing options...
Barand Posted November 11, 2008 Share Posted November 11, 2008 Use arrays for the form fields too, don't append numbers to the names for ($i = 0; $i < 40; $i++) { echo "<input type='hidden' name='model_number[$i]' value='{$model_number[$i]}' >"; } Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 11, 2008 Share Posted November 11, 2008 That means you are not normal either.I'm a techno-geek! Who wants to be normal? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.