Jump to content


This topic is now archived and is closed to further replies.

Andrew R

Echoing multiple fields depending on a variable

Recommended Posts

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

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

[code]<table width="306" border="0" cellpadding="2" cellspacing="3">
    <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>
    <td width="1">&nbsp;</td>

Can this be done using?  [code]<?php do { ?> ?[/code]

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


Share this post

Link to post
Share on other sites
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"

so this will match up with the database structure

Share this post

Link to post
Share on other sites


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.