newtoall Posted May 22, 2007 Share Posted May 22, 2007 I hope someone who has a bit more PHP knowledgeable than me can explain why the following is happening and suggest a wat to fix it…..: Basically I have a form that contains a table and is used to update information in a mysql database. The form displays multiple rows of information and in the following example seems to work OK (I have chopped the table down a bit): <form name='timesheetForm' method='post' action=''> <table bgcolor='#CCD6E4'> <tr> <tr> <td><font size="2" face="Arial, Helvetica, sans-serif"> Project code</td> <td><font size="2" face="Arial, Helvetica, sans-serif">Monday</td> <td><font size="2" face="Arial, Helvetica, sans-serif">Totals</td> </tr> <td><input type='text' name='ProjectCode[]' value="<?php echo $TimesheetP[$i][0];?>" size=10 maxlength=10></td> <td><input type='text' name='MonTime[]' value="<?php echo $TimesheetP[$i][5];?>" size=10 maxlength=10></td> <td><input type='text' name='TotalTime[]' value="<?php echo $TimesheetP[$i][12];?>" size=10 maxlength=10></td> </tr> <?php } ?> <tr> <td colspan=9 align='right'> <input type='submit' value='Submit Timesheet'></td></tr> </table></form> However when I add a select value into the table only one row is returned, and it looks like the select stops the outer loop from working, I was hoping someone could tell me why??: <form name='timesheetForm' method='post' action=''> <table bgcolor='#CCD6E4'> <tr> <tr> <td><font size="2" face="Arial, Helvetica, sans-serif"> Project code</td> <td><font size="2" face="Arial, Helvetica, sans-serif">Monday</td> <td><font size="2" face="Arial, Helvetica, sans-serif">Totals</td> </tr> <?php for($i = 0; $i<$TimesheetPs; $i++) { ?> <tr> <td><select name = "ProjectCode[]"> <?php for($i = 0; $i<$project_lists; $i++) { echo '<option value = '.$project_list[$i][0]; if ($TimesheetP[$i][0] == $project_list[$i][0]) echo ' selected'; echo '>'.$project_list[$i][1]."</option>\n"; } ?></select></td> <td><input type='text' name='MonTime[]' value="<?php echo $TimesheetP[$i][5];?>" size=10 maxlength=10></td> <td><input type='text' name='TotalTime[]' value="<?php echo $TimesheetP[$i][12];?>" size=10 maxlength=10></td> </tr> <?php } ?> <tr> <td colspan=9 align='right'> <input type='submit' value='Submit Timesheet'></td></tr> </table></form> Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/52455-php-in-a-form-problem/ Share on other sites More sharing options...
colombian Posted May 22, 2007 Share Posted May 22, 2007 Here are some quick guesses: for($i = 0; $i<$project_lists; $i++) { echo '<option value = '.$project_list[$i][0]; if ($TimesheetP[$i][0] == $project_list[$i][0]) { echo ' selected'; //added some curly brackets around this, always good to do on an if statement } else {''} //what do you want it to do if this is not the first item? echo '>'.$project_list[$i][1]."</option>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/52455-php-in-a-form-problem/#findComment-259093 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.