arneman Posted July 7, 2009 Share Posted July 7, 2009 I want to give my users a chance to change their profile. But I want the selectable date to show up in comboboxes but the data from the MySQL DB should be selected. For the gender I managed to solve this with a simple IF structure. But I'm not planning on doing this 12 times for the months or even 60 times for the years. I'm looking forward to hearing your ideas. My current code is at : http://www.plaatscode.be/137085 Quote Link to comment https://forums.phpfreaks.com/topic/165093-profile-page/ Share on other sites More sharing options...
ignace Posted July 7, 2009 Share Posted July 7, 2009 Dutch: Waarom zijn alle belgen toch zo lui? $months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December'); $years = array(); $currentYear = (int) date('Y'); for ($i = $currentYear; $i > $currentYear - 100; --$i) { // sorry 100+ shouldn't surf the web $years[] = $i; } Quote Link to comment https://forums.phpfreaks.com/topic/165093-profile-page/#findComment-870573 Share on other sites More sharing options...
MatthewJ Posted July 7, 2009 Share Posted July 7, 2009 Are you saying that you want the month/day/year selected that is the same as the date being pulled from the db? If so, just add an if to your loops that generate the select menus <select name="year"> <?php $yearfrommysql = 1975; for($i = 1960; $i < 2040; $i++) { if($yearfrommysql == $i) { echo "<option value='$i' selected='selected'>$i</option>\n"; } else { echo "<option value='$i'>$i</option>\n"; } } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/165093-profile-page/#findComment-870577 Share on other sites More sharing options...
ignace Posted July 7, 2009 Share Posted July 7, 2009 This 5 lines of code do the same thing your 15 lines of code do <select name="gender"> <option>-</option> <option value="1"<?php $gender === 1 ? ' selected="selected"' : '' ?>>Male</option> <option value="2"<?php $gender === 2 ? ' selected="selected"' : '' ?>>Female</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/165093-profile-page/#findComment-870597 Share on other sites More sharing options...
MatthewJ Posted July 7, 2009 Share Posted July 7, 2009 I'm still wondering what the op was asking for Quote Link to comment https://forums.phpfreaks.com/topic/165093-profile-page/#findComment-870601 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.