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>

Link to comment
Share on other sites

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.

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.