Scooby08 Posted September 3, 2008 Share Posted September 3, 2008 I'm having a hard time figuring out how I can accomplish this.. I have a form that is dynamically generated from the database and has a foreach loop to display each field.. Now I'm working on the edit information form.. The problem is that I cannot figure out how to get the field values inserted into the dynamically generated form.. Below is the snipplet I'm working with: <?php // select values in database to display in the field values $query_ci = "SELECT firstname, lastname, email FROM dw_customers WHERE customer_id = '$customer_id' "; $result_ci = mysql_query($query_ci) or die(mysql_error()); while ($row_ci = mysql_fetch_array($result_ci)) { $field_values = $row_ci; // array of info I need inserted into the form values for each field } // select fieldnames to build dynamic form $query_fields = "SELECT * FROM dw_fields "; $result_fields = mysql_query($query_fields) or die(mysql_error()); $set_fields = array(); while ($row_fields = mysql_fetch_object($result_fields)) { $set_fields[$row_fields->field_category][] = $row_fields; } foreach ($set_fields as $field_category => $records) { ?> <fieldset class="fieldsetForm"> <legend><?=$field_category;?></legend> <div class="centerFormInfoWrap"> <?php foreach ($records as $row_fields) { ?> <label><?=$row_fields->field_name;?></label> <input type="<?=$row_fields->field_form_type;?>" name="<?=$row_fields->field_form_name;?>" value="" id="<?=$row_fields->field_form_name;?>" maxlength="<?=$row_fields->field_form_maxlength;?>" /><br /> <?php } ?> </div> <div class="clear"></div> </div> </fieldset> <?php } ?> From that first SELECT I made a foreach like so to display the values: <?php foreach ($field_values as $field_value) { echo $field_value; } ?> Works great by itself, but if I put that into the foreach that displays all the fields, then I get multiple displays of each field and values where as I just need one of each.. What might I need to do here?? Link to comment https://forums.phpfreaks.com/topic/122486-foreach-loop-display-information/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.