moondran Posted January 6, 2012 Share Posted January 6, 2012 Hi Guys need some help with this: On my first page I generate a form with a while loop from a table with employees. I’m not going to paste my whole code for fast reading: While($myrow = $result ->fetch_assoc()){ $emp_id = $myrow[“id”]; $emp_name = $myrow[“name”]; $display .= <<<EOF_ <input type="hidden" name="monday_$emp_id" id=" monday_$emp_id" value="$monday" /> <input type="hidden" name="tuesday_$emp_id " id="tuesday_$emp_id" value="$tuesday " /> EOF_; } I give each field the name ie. monday_$emp_id to give them each unique names: My question is how do I recall those variables on my input page? On my input page I use a foreach to get all the variables but need to enter them into a table with the fields (emp_id, monday,tuesday) etc. The problem is that the variables on the input page is ie. $Monday_23 and the number 23 can be anything depending on the employee id. I have managed with explode() to get the emp_id and tried to use $Monday = $Monday_{$emp__id}; but that doesn’t seem to work. Thanks Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted January 6, 2012 Share Posted January 6, 2012 People don't mind to read here, post your entire code including the form. I believe is easier ways, and will help us understand it more. Quote Link to comment Share on other sites More sharing options...
moondran Posted January 6, 2012 Author Share Posted January 6, 2012 The code is irrelevant to question really, All I want to know if there is a way to echo or use the variable if you have the following: In a nut shell this is what I have. A textField called Monday_$emp_id in a while loop. Lets say I’m working with the 1st employee for the example. So on my input page I will have this. $Monday_1 = “100”; I know I have a variable on the input page called $Monday_unknownNumber but the unknownNumber is the id of the employee so I can get it. $emp_id=”1”; The unknown number above is always the id of an employee so I can get it. So for me to echo it or use it I need to do something like the following. echo “$Monday_{$emp_id}”; this is the part I’m looking for, this code obviously doesn’t work. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 6, 2012 Share Posted January 6, 2012 why don't you just make the form element names arrays to begin with? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 6, 2012 Share Posted January 6, 2012 As Muddy_Funster stated you should create the form fields as arrays with the IDs as the indexes for the array. However, what you are doing for the id parameter of the fields is fine since you don't access those on the PHP receiving page. Also, no need to assign the database fields to a temporary variable if you are not going to use it later - just use the array value in the output. Example format: While($myrow = $result ->fetch_assoc()){ $emp_name = $myrow['name']; $display .= <<<EOF_ <input type="hidden" name="monday[{$myrow['id']}]" id=" monday_$emp_id" value="$monday" /> <input type="hidden" name="tuesday[{$myrow['id']}] " id="tuesday_$emp_id" value="$tuesday " /> EOF_; } Now you can access all the "monday" values using a foreach loop such as foreach($_POST['monday'] as $empID => $mondayValue) { // } 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.