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> Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/ 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)) Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/#findComment-1404103 Share on other sites More sharing options...
a65 Posted January 8, 2013 Author Share Posted January 8, 2013 now i am getting reset()expects parameter 1 to be array Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/#findComment-1404104 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... Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/#findComment-1404107 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. Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/#findComment-1404110 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. Link to comment https://forums.phpfreaks.com/topic/272830-dta-is-not-being-fetched-in-both-the-combobox/#findComment-1404150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.