pakenney38 Posted November 17, 2006 Share Posted November 17, 2006 Does anyone know how to echo HTML table rows based on a loop?For example, I have this code that doesn't work. Assume that $addrow is set via a submit button.With this said, rowcount should be equal to 5 on the intial page load. After the script runs, it should be equal to 10.[code]if (isset($addrow)){for ($x = ($rowcount + 1); $x <= ($rowcount + 5); $x++) {echo " <tr> <td><label> <div align='center'> <input name='date$x' type='text' id='date$x' size='10' /> </div> </label></td> <td><div align='center'> <label> <input name='fltno$x' type='text' id='fltno$x' size='5' /> </label> </div></td> <td><div align='center'> <input name='actblk$x' type='text' id='actblk$x' size='5' /> </div></td> <td><div align='center'> <input name='schblk$x' type='text' id='schblk$x' size='5' /> </div></td> <td><div align='center'> <input name='dhcr$x' type='text' id='dhcr$x' size='8' /> </div></td> <td><div align='center'> <input name='paycr$x' type='text' id='paycr$x' size='8' /> </div></td> <td><div align='center'> <input name='nontax$x' type='text' id='nontax$x' size='8' /> </div></td> <td><div align='center'> <input name='tax$x' type='text' id='tax$x' size='8' /> </div></td> <td><div align='center'> <label> <input name='comments$x' type='text' id='comments$x' size='52' /> </label> </div></td> </tr>"; }$rowcount = $x;echo "<input name='rowcount' type='hidden' id='rowcount' />";}else {$rowcount = 5;echo "<input name='rowcount' type='hidden' id='rowcount' />";}[/code] Quote Link to comment Share on other sites More sharing options...
esukf Posted November 17, 2006 Share Posted November 17, 2006 Note exactly sure what you're after but see if the following helps.[code]<?php$rowcount = 5; //default number of rowsif (isset($addrow)){ $rowcount = $rowcount + 5; //add 5 rows if $addrow is set} for ($x = 1; $x <= $rowcount; $x++){ echo " <tr> <td><label> <div align='center'> <input name='date$x' type='text' id='date$x' size='10' /> </div> </label></td> <td><div align='center'> <label> <input name='fltno$x' type='text' id='fltno$x' size='5' /> </label> </div></td> <td><div align='center'> <input name='actblk$x' type='text' id='actblk$x' size='5' /> </div></td> <td><div align='center'> <input name='schblk$x' type='text' id='schblk$x' size='5' /> </div></td> <td><div align='center'> <input name='dhcr$x' type='text' id='dhcr$x' size='8' /> </div></td> <td><div align='center'> <input name='paycr$x' type='text' id='paycr$x' size='8' /> </div></td> <td><div align='center'> <input name='nontax$x' type='text' id='nontax$x' size='8' /> </div></td> <td><div align='center'> <input name='tax$x' type='text' id='tax$x' size='8' /> </div></td> <td><div align='center'> <label> <input name='comments$x' type='text' id='comments$x' size='52' /> </label> </div></td> </tr>";}//Not sure what you are trying to do which the hidden inputsecho "<input name='rowcount' type='hidden' id='rowcount' />";?>[/code] 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.