Anzeo Posted March 29, 2007 Share Posted March 29, 2007 Hi, I'm currently developping my own user system and so far I've completed my registration and profile but now I'm stuck on a problem at my edit file. I do'nt have a clue on how to insert mysql entries, like the birthday of the user back into the drop-down list (<select>) or options they choosed back into the checkboxes. Does anyone know how to do this? I do know how to put mysql entries back into textfields but I can't figure out how to do this for the other form items. TIA Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/ Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 you need to describe what you want to do more efficiently. help us help you. Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217717 Share on other sites More sharing options...
Anzeo Posted March 29, 2007 Author Share Posted March 29, 2007 Well, my users use a list like this <select name="Name" id="ID"> <option value="0" selected> </option> ... To insert their birthdate in my db. Now when you click edit profile I'd like to have their birthday show in the lists so that it shows like: [2] / [9] / [1960] with the '[]' representing the <select> lists. The same goes for the checkboxes. The user can select some option to adjust the site to his likes and when editting your profile I want the option you've chosen to be selected and the ones you didn't to be deslected Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217733 Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 so you want to dynamically change the pre-selected dropdowns, right? Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217748 Share on other sites More sharing options...
Anzeo Posted March 29, 2007 Author Share Posted March 29, 2007 Yes, indeed Thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217749 Share on other sites More sharing options...
Barand Posted March 29, 2007 Share Posted March 29, 2007 perhaps <?php function dropDown ($name, $min, $max, $current) { $str = "<select name='$name'>\n"; $opts = range($min, $max); foreach ($opts as $opt) { $sel = $opt==$current ? 'selected' : ''; $str .= "<option $sel> $opt</option>\n"; } $str .= "</select>\n"; return $str; } $dob = '2/9/1960'; list ($m, $d, $y) = explode('/', $dob); echo dropDown('month', 1, 12, $m), ' / ', dropDown('day', 1, 31, $d) , ' / ', dropDown('year', 1907, 2007, $y); ?> Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217797 Share on other sites More sharing options...
boo_lolly Posted March 30, 2007 Share Posted March 30, 2007 i'd do: <?php $sql = "SELECT * FROM your_table"; $query = mysql_query($sql) OR die(mysql_error()); echo "<form action=\"\" method=\"post\">\n"; echo "<select name=\"drop_down\">\n"; while($row = mysql_fetch_array($query)){ echo "<option value=\"{$row['cloumn1']}\"". (($row['column1'] == $_POST['drop_down']) ? (" SELECTED") : ("")) .">{row['column2']}\n"; } echo "<input type=\"submit\" value=\"Submit\">\n"; echo "</form>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-217904 Share on other sites More sharing options...
Anzeo Posted March 30, 2007 Author Share Posted March 30, 2007 Thanks for your replies. I can't check if their working right now as I'm at school, but I'll be able to try the scripts by sunday. @boo_lolly: does your script checks if that's the selected option? I can't realy tell, as I'm currently learning PHP myself and have only 'mastered' the basics this far. I appreciate your time and help Grtz, Anzeo Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-218122 Share on other sites More sharing options...
boo_lolly Posted March 30, 2007 Share Posted March 30, 2007 Thanks for your replies. I can't check if their working right now as I'm at school, but I'll be able to try the scripts by sunday. @boo_lolly: does your script checks if that's the selected option? I can't realy tell, as I'm currently learning PHP myself and have only 'mastered' the basics this far. I appreciate your time and help Grtz, Anzeo yes it does =) this is the part that checks to see if it's selected: (($row['column1'] == $_POST['drop_down']) ? (" SELECTED") : ("")) Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-218361 Share on other sites More sharing options...
Anzeo Posted April 2, 2007 Author Share Posted April 2, 2007 It works great! Thanks alot for your help. Quote Link to comment https://forums.phpfreaks.com/topic/44834-solved-listing-mysql-results-in-a-or-checkbox-item/#findComment-219832 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.