a65 Posted January 8, 2013 Share Posted January 8, 2013 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> Quote Link to comment Share on other sites More sharing options...
haku Posted January 8, 2013 Share Posted January 8, 2013 You need to reset the internal pointer to the first element before you can use $result again: <tr><td>account to transfer</td><td><select name="accountname2"> <?php reset($result); while($row=mysql_fetch_assoc($result)) Quote Link to comment Share on other sites More sharing options...
a65 Posted January 8, 2013 Author Share Posted January 8, 2013 (edited) now i am getting reset()expects parameter 1 to be array Edited January 8, 2013 by a65 Quote Link to comment Share on other sites More sharing options...
a65 Posted January 8, 2013 Author Share Posted January 8, 2013 again writing the query solved my problem... Quote Link to comment Share on other sites More sharing options...
haku Posted January 8, 2013 Share Posted January 8, 2013 Apologies, wrong function. mysql_data_seek() is the function you want, not reset(). reset() is for arrays, as the error you are seeing is informing you. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 8, 2013 Share Posted January 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.