Jump to content


Photo

Echoing multiple fields depending on a variable


  • Please log in to reply
3 replies to this topic

#1 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 13 October 2006 - 05:23 PM

Hi, I need some help echoing a certain amount of fields depending on how much the variable, $total_user equals.

For example if
$total_user = ‘6‘
it will echo the below fields (name, age forms six times)

<table width="306" border="0" cellpadding="2" cellspacing="3">
  <!--DWLayoutTable-->
  <tr> 
    <td width="45" height="28" valign="middle"><strong>Name:</strong></td>
    <td width="144" valign="top"><input name="name" type="text" id="name"></td>
    <td width="32" valign="middle"><strong>Age:</strong></td>
    <td width="48" valign="top"><select name="select">
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
      </select></td>
    <td width="1">&nbsp;</td>
  </tr>
</table>

Can this be done using? 
<?php do { ?> ?

Also how would I label each field so that they can be entered into the database, i.e the input name.

Cheers


#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 13 October 2006 - 05:25 PM

for ($i = 1; $i <= $total_count; $i++)
{
      // Do stuff here
}



#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 13 October 2006 - 05:26 PM

What do you mean by labelling them?

#4 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 13 October 2006 - 05:40 PM

For example if the variable equals 4 people, 4 fields will appear and the input name for each field will be :
input name="User_1"  value="bob"
input name="User_2"  Value="andy"
input name="User_3"  Value="sam"
Input name="User_4"  Value="jim"
etc

so this will match up with the database structure





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users