drummer101 Posted November 29, 2008 Share Posted November 29, 2008 So I've got a date select box, what I'd like to do is query the database for the date, and have the date in the database show up in the date select box (<option selected="selected">) but I can't quite wrap my brain around how to do it, and keep them in numerical order. // Month Select Box echo "<select>"; for($m=1; $m<=12; $m=$m+1){ echo "<option value=\"$m\" name=\"month\">$m</option>"; } echo "</select>"; // Day Select Box echo "<select>"; for($d=1; $d<=31; $d=$d+1){ echo "<option value=\"$d\" name=\"day\">$d</option>"; } echo "</select>"; // Year Select Box echo "<select>"; for($y=2008; $y>=2008; $y=$y-1){ echo "<option value=\"$y\" name=\"year\">$y</option>"; } [/php Link to comment https://forums.phpfreaks.com/topic/134799-solved-select-boxquery-from-database/ Share on other sites More sharing options...
.josh Posted November 29, 2008 Share Posted November 29, 2008 Assuming that you retrieved your date from the database and split it up into vars... echo "<select>"; for($m=1; $m<=12; $m=$m+1){ $selected = ($m == $month)? 'selected' : ''; echo "<option value=\"$m\" name=\"month\" $selected>$m</option>"; } echo "</select>"; Link to comment https://forums.phpfreaks.com/topic/134799-solved-select-boxquery-from-database/#findComment-701950 Share on other sites More sharing options...
drummer101 Posted November 30, 2008 Author Share Posted November 30, 2008 Assuming that you retrieved your date from the database and split it up into vars... echo "<select>"; for($m=1; $m<=12; $m=$m+1){ $selected = ($m == $month)? 'selected' : ''; echo "<option value=\"$m\" name=\"month\" $selected>$m</option>"; } echo "</select>"; Would that not return ALL values as selected? The code I posted above builds the select box and populates it with values. Link to comment https://forums.phpfreaks.com/topic/134799-solved-select-boxquery-from-database/#findComment-701957 Share on other sites More sharing options...
drummer101 Posted November 30, 2008 Author Share Posted November 30, 2008 Oh right, I get it. Link to comment https://forums.phpfreaks.com/topic/134799-solved-select-boxquery-from-database/#findComment-701968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.