Jump to content

<option value...> selected from MySQL


InGale
 Share

Recommended Posts

Hello!I have this SELECT field in my form:

<select name="issue_month" id="issue_month">			<option value="0" selected="selected">Select month</option>			<option value="Jan">January</option>			<option value="Feb">February</option>			<option value="Mar">March</option>			<option value="Apr">April</option>			<option value="May">May</option>			<option value="Jun">June</option>			<option value="Jul">July</option>			<option value="Aug">August</option>			<option value="Sep">September</option>			<option value="Oct">October</option>			<option value="Nov">November</option>			<option value="Dec">December</option>		  </select>

when I retrieve this data from MySQL it's $issue_month = $row['issue_month'];Now, if the record says May, for example, how can I make May be selected automatically in this field, so it would look like this:

<select name="issue_month" id="issue_month">			<option value="0">Select month</option>			<option value="Jan">January</option>			<option value="Feb">February</option>			<option value="Mar">March</option>			<option value="Apr">April</option>			<option value="May" selected="selected">May</option>			<option value="Jun">June</option>			<option value="Jul">July</option>			<option value="Aug">August</option>			<option value="Sep">September</option>			<option value="Oct">October</option>			<option value="Nov">November</option>			<option value="Dec">December</option>		  </select>

Thanks!!

Link to comment
Share on other sites

Hello!I have this SELECT field in my form:
<?php $ans = '<select>';$getmonth = 'mar';//get month from data base or anyware$getmonth = strtolower($getmonth);$month = array('jan'=>'January',		'feb'=>'Feburary',		'mar'=>'March',		'apr'=>'April',		'may'=>'May',		'jun'=>'Jun',		'jul'=>'July',		'aug'=>'August',		'sep'=>'September',		'oct'=>'October',		'nov'=>'Novemver',		'dec'=>'December');foreach($month as $value => $name){	if($value == $getmonth)	{		$ans .="<option selected=\"selected\" value=\"$value\">$name</option>";	}	else	{		$ans .="<option value=\"$value\">$name</option>";	}}  echo $ans."</select>";?>

Tested On http://www.mscyber.com/php/

Link to comment
Share on other sites

Its Not So Difficult Try This
<?php $ans = '<select>';$getmonth = 'mar';//get month from data base or anyware$getmonth = strtolower($getmonth);$month = array('jan'=>'January',		'feb'=>'Feburary',		'mar'=>'March',		'apr'=>'April',		'may'=>'May',		'jun'=>'Jun',		'jul'=>'July',		'aug'=>'August',		'sep'=>'September',		'oct'=>'October',		'nov'=>'Novemver',		'dec'=>'December');foreach($month as $value => $name){	if($value == $getmonth)	{		$ans .="<option selected=\"selected\" value=\"$value\">$name</option>";	}	else	{		$ans .="<option value=\"$value\">$name</option>";	}}  echo $ans."</select>";?>

Tested On http://www.mscyber.com/php/

I tried it, changed this part only: $getmonth = $issue_month;But I always get January selected...
Link to comment
Share on other sites

I tried it, changed this part only: $getmonth = $issue_month;But I always get January selected...
Which variabel or string is assign to $issue_month. I mean What is the Value of $issue_monthfirst check out your database and the value which you r getting from data base is same as in option value. then it will work fine... Edited by samgenius
Link to comment
Share on other sites

Which variabel or string is assign to $issue_month. I mean What is the Value of $issue_monthfirst check out your database and the value which you r getting from data base is same as in option value. then it will work fine...
Well, I have the months names written in Russian, so when I echoed the $issue_month - I got the month name in Russian, as it's supposed to be; but when I echoed the $getmonth after the lower case function, I got this - ������... Any way to avoid it?
Link to comment
Share on other sites

Well, I have the months names written in Russian, so when I echoed the $issue_month - I got the month name in Russian, as it's supposed to be; but when I echoed the $getmonth after the lower case function, I got this - ������... Any way to avoid it?
set the value of option in eng eg:<option value="feb">Russian Feburary</option>change The array also'feb'=>'Russian Feburary',
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...