Jump to content

Default value in combobox for edit data in form


ebchost

Recommended Posts

I trying to display data from a database for editing

 

I have 2 table:

 

1. tbl_proizvodi_karakteristike (Translate: tbl_product_caracteristics)

- In this table i have list of product caracteristic relatet to product 'id' in table 'tbl_product_list' (this 'tbl_product_list' is not important now)

- field: id, opis, vrednsot, proizvod_id

 

2. tbl_karakteristike (Translate: tbl_caracteristic)

- In this table i have list of all caracteristic

- field: id, opis

 

in field 'opis' in table 'tbl_proizvodi_karakteristike' i insert 'id' from 'tbl_karkateristike' and that works ok with combo box.

But, when  i try to edit value in 'tbl_proizvodi_karakteristike', i do not know how to show current value in combo box (i have list of value from 'tbl_karakteristike' in combox, starting from first)

For examle, if i know that value in selected caracteristics is 'opis = 25', it means that i in combo box on load edit form mast have first value 25 and rest of posible value. For now i have value '1 and rest of value'

 

Hiar is current code in edit form

 

<form action='product_carasteristic.php?product_id=<?php echo $p_id; ?>&product_name=<?php echo $p_name; ?>' method='POST'>
<?php
		$p_id = $_GET['id'];
		$karakteristike = mysql_query("SELECT * FROM `tbl_proizvodi_karakteristike` WHERE `id`='$p_id'") or die(mysql_error());
		while($row = mysql_fetch_array($karakteristike)){
					$p_id           = $row['id'];
					$p_opis         = $row['opis'];
					$p_vrednost     = $row['vrednost'];
					$p_proizvod_id  = $row['proizvod_id'];
		?>
<table>
	<tr>
		<td >
			Karakteristika   
		</td>
		<td>
			<select name="opis"  style="font-family: verdana; font-size:15px; width:342px;">
			<?php
				$tbl_karakteristike = mysql_query("SELECT * FROM `tbl_karakteristike`") or die(mysql_error());
				while($row = mysql_fetch_array($tbl_karakteristike)){
					$k_id           = $row['id'];
					$k_opis         = $row['opis'];					
			?>				
					<option value='<?php echo $k_id; ?>'><?php echo $k_opis; ?></option>				
			<?php
				}
			?>
			</select>
		</td>
	</tr>
	<tr>
		<td>
			Vrednost karakteristike    
		</td>
		<td>
			<input type="text" name="vrednost" value='<?php echo $p_vrednost; ?>'>				
		</td>
	</tr>		
	<tr>
		<td>
		<input type="submit" name="submit" value="Kreiraj">
		</td>
		<td>
		Neophodno je popuniti sva polja
		</td>
	</tr>
</table>
<?php
	}
?>
</form>

 

thanks forward :)

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.