Jump to content

displaying input box with select in loop


mraza

Recommended Posts

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

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); ?>

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.