mraza Posted August 17, 2010 Share Posted August 17, 2010 hi i am in situation to display input box along with select option , here is my code <?php $run= $dbc->db("SELECT * FROM `table` WHERE `id`='$id'"); ?> <select name="service"> <?php while ($result = mysql_fetch_array($run)) { ?> <option value="<?php echo $result['id'] ; ?>"><?php echo $result['service'] ; ?></option> <?php // This is problem i need to get this as hidden field but it breaks my select options. ?> <input type="hidden" value="<?php echo $result['data'] ; ?>" name="data" /> <?php } ?> </select> so here i am stuck <input type="hidden" value="<?php echo $result['id'] ; ?>" name="data" /> when i repeat in while loop it breaks options box and display other options without in select box. any help please thanks Link to comment https://forums.phpfreaks.com/topic/210907-displaying-input-box-with-select-in-loop/ Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 Try storing the hidden fields in an array, then imploding them after you close the select box. <?php $run = $dbc->db("SELECT * FROM `table` WHERE `id`='$id'"); ?> <select name="service"> <?php $hidden = array(); while ($result = mysql_fetch_array($run)) { ?> <option value="<?php echo $result['id'] ; ?>"><?php echo $result['service'] ; ?></option> <?php $hidden[] = '<input type="hidden" value="'. $result['data'] . '" name="data" />'; } ?> </select> <?php echo implode("\n", $hidden); ?> Link to comment https://forums.phpfreaks.com/topic/210907-displaying-input-box-with-select-in-loop/#findComment-1100043 Share on other sites More sharing options...
mraza Posted August 17, 2010 Author Share Posted August 17, 2010 Thank you very much sir for your help. its solved Link to comment https://forums.phpfreaks.com/topic/210907-displaying-input-box-with-select-in-loop/#findComment-1100051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.