InGale Posted August 2, 2011 Share Posted August 2, 2011 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 More sharing options...
samgenius Posted August 2, 2011 Share Posted August 2, 2011 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 More sharing options...
InGale Posted August 2, 2011 Author Share Posted August 2, 2011 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 More sharing options...
samgenius Posted August 2, 2011 Share Posted August 2, 2011 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... Link to comment Share on other sites More sharing options...
InGale Posted August 2, 2011 Author Share Posted August 2, 2011 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 More sharing options...
samgenius Posted August 3, 2011 Share Posted August 3, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.