Jump to content

dynamically echo HTML table rows


pakenney38

Recommended Posts

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]
Link to comment
Share on other sites

Note exactly sure what you're after but see if the following helps.
[code]<?php

$rowcount = 5; //default number of rows

if (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 inputs
echo "<input name='rowcount' type='hidden' id='rowcount' />";

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.