Jump to content

dta is not being fetched in both the combobox


a65

Recommended Posts

why i am not able to show the fetched data in both the combobox. it is being shown in only one combobox

<tr><td>account from transfer</td><td><select name="accountname">
<?php
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?php echo($row['account_name']); ?>"><?php echo($row['account_name']); ?></option>
<?php
}
?>
</select>
</td>
</tr>


<tr><td>account to transfer</td><td><select name="accountname2">
<?php
while($row=mysql_fetch_assoc($result))
{
?>
<option value="<?php echo($row['account_name']); ?>"><?php echo($row['account_name']); ?></option>
<?php
}
?>
</select>
</td></tr>

An even better way to do this would be to construct both drop-downs in the first loop, using a variable to hold the constructed data. Considering the fact that both dropdowns contain the exact same data, this is by far the most preferred solution.

 

$dropTemplate = '<option value="%s">%1$s</option>'."\n";
$dropOptions = '';
while ($row = $res->fetch_row ()) {
   $dropOptions .= sprintf ($dropTemplate, htmlspecialchars ($row['account_name'));
}

 

Then just echo out $dropOptions where you want the options.

Archived

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

×
×
  • 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.