turpentyne Posted March 22, 2012 Share Posted March 22, 2012 Looking for tutorials, but maybe the forum's quicker. Can anybody give me a loose idea how to do this? I have a sequence of pages that the user goes through to enter information. I need to move a page up to pull data before inputting to the database - to prevent some dropped entries and errors. Before, it was using info in the database to loop through and generate data. I want to do it just based on the info in an array: I want array(217 => 1, 215 => 2); to loop generate a form that loops through to create something like: <form> Student one, Class 217<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><hr><br> Student one, Class 215<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><br> Student one, Class 215<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><hr><br> and so on. <input type="submit" value="Register" /></form> Link to comment https://forums.phpfreaks.com/topic/259462-create-fields-based-on-array/ Share on other sites More sharing options...
rythemton Posted March 22, 2012 Share Posted March 22, 2012 foreach( $array AS $key=>$value ) { for( $i; $i < $value; $i++ ) { echo 'Class: ' . $key; /* Create form here */ echo '<br><br>'; } echo '<br>'; } Link to comment https://forums.phpfreaks.com/topic/259462-create-fields-based-on-array/#findComment-1330084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.