rik72 Posted October 19, 2008 Share Posted October 19, 2008 Hi, i have a very quick problem; I have my selectbox in HTML on an "edit account" page. <select name="mm" id="mm"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> For normal fields i am doing this; <input type="text" name="email" maxlength="50" value=" <? if($form->value("email") == ""){ echo $session->userinfo['email']; }else{ echo $form->value("email"); } ?>"> How would i work this on a selectbox field? Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/ Share on other sites More sharing options...
cunoodle2 Posted October 19, 2008 Share Posted October 19, 2008 Here are 2 that I used for month and day. This should help you out I think... <td width="79%"><select size="1" name="billing_renew_month"> <option<?php if ($month_of_year == 1) echo " SELECTED"; ?> value="1">January</option> <option<?php if ($month_of_year == 2) echo " SELECTED"; ?> value="2">February</option> <option<?php if ($month_of_year == 3) echo " SELECTED"; ?> value="3">March</option> <option<?php if ($month_of_year == 4) echo " SELECTED"; ?> value="4">April</option> <option<?php if ($month_of_year == 5) echo " SELECTED"; ?> value="5">May</option> <option<?php if ($month_of_year == 6) echo " SELECTED"; ?> value="6">June</option> <option<?php if ($month_of_year == 7) echo " SELECTED"; ?> value="7">July</option> <option<?php if ($month_of_year == echo " SELECTED"; ?> value="8">August</option> <option<?php if ($month_of_year == 9) echo " SELECTED"; ?> value="9">September</option> <option<?php if ($month_of_year == 10) echo " SELECTED"; ?> value="10">Ocotober</option> <option<?php if ($month_of_year == 11) echo " SELECTED"; ?> value="11">November</option> <option<?php if ($month_of_year == 12) echo " SELECTED"; ?> value="12">December</option> </select> <select size="1" name="billing_renew_day"><?php //write out all the options for 1-31 days for ($jj = 1; $jj < 32; $jj++) { echo "\n\t <option "; if ($day_of_month == $jj) echo "SELECTED "; echo "value\"=".$jj."\">".$jj."</option>"; }?> Try that out and see if that helps your situation. Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669390 Share on other sites More sharing options...
cunoodle2 Posted October 19, 2008 Share Posted October 19, 2008 Also try this. This will 100% automate writing out all of the names of the month so you don't have to manually type them out... <?php for ($i = 1; $i < 13; $i++) { echo "\n\t <option "; if ($month_of_year == $i) echo "SELECTED "; echo "value\"=".$i."\">".date("F", $i)."</option>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669392 Share on other sites More sharing options...
rik72 Posted October 19, 2008 Author Share Posted October 19, 2008 Thanks! Just one more error now; With the code you gave me for generating days, How can i make it so that it is always two digits long? 01 02.. ..29 30 31 etc? Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669435 Share on other sites More sharing options...
wildteen88 Posted October 19, 2008 Share Posted October 19, 2008 Change echo "value\"=".$jj."\">".$jj."</option>"; to sprintf('value="%02d">%02d</option>', $jj); Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669446 Share on other sites More sharing options...
rik72 Posted October 19, 2008 Author Share Posted October 19, 2008 Change echo "value\"=".$jj."\">".$jj."</option>"; to sprintf('value="%02d">%02d</option>', $jj); I'm getting this error; sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in <b>/home/altshop/public_html/new/useredit.php</b> on line <b>132</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669453 Share on other sites More sharing options...
wildteen88 Posted October 19, 2008 Share Posted October 19, 2008 Oops. Should of been printf('value="%1$02d">%1$02d</option>', $jj); Quote Link to comment https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/#findComment-669457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.