Jump to content

A diffrent selected value of a select form depending on a var


son.of.the.morning

Recommended Posts

I need my select dropdown to show the relevant option. I am using a GET action to pass the id of an article to another page (edit article page) with this i am selecting that specific record and passing it's data into form object in order to be modified and updated. The only issue is my category list is a dropdown and i need it to display the relivent category for that specific record.

 

hope that makes sence

Link to comment
Share on other sites

<?php 

if(isset($_GET['id'])) {
	$id = $_GET['id'];	
	$a = "SELECT * FROM blog_posts WHERE id = $id";
	$query  = mysql_query($a) or die (mysql_error());
	$return = mysql_fetch_array($query);
}
else {
}
?>

 

<select name="color" class="SelectColor">
        <option id="red" value="red">red</option>
        <option id="blue" value="blue">blue</option>
        <option id="green" value="green">green</option>
        <option id="grey" value="grey">grey</option>
</select>

Link to comment
Share on other sites

Untested, unproof-read; however...

 

<?PHP
$colors = array("red","blue","green","grey");
$color_count = count($colors);
$what_color = "blue"; /* use the color from wherever to set this variable */
?>

<select name="color" class="SelectColor">
<?PHP
for($i=0;$i<$color_count;$i++) {
	?>
	<option id="<?PHP echo $colors[$i]; ?>" value="<?PHP echo $colors[$i]; 
		if($what_color == $colors[$i]) {
			echo "SELECTED"; 
		}
		?>">
		<?PHP echo $colors[$i]; ?>
	</option>
<?PHP
}
?>
</select>

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.