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

Link to comment
Share on other sites

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
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.