yarub Posted June 5, 2006 Share Posted June 5, 2006 [code]$query = mysql_query("select * FROM table WHERE id='$id'");$row = mysql_fetch_array($query);<select name='month'> <option value='Jan'>January <option value='Feb'>February <option value='Mar'>March <option value='Apr'>April <option value='May'>May <option value='Jun'>June <option value='Jul'>July <option value='Aug'>August <option value='Sep'>September <option value='Oct'>October <option value='Nov'>November <option value='Dec'>December</select>[/code]How can I pull what the user has from my database? With the text type you just use value='$whatever'. With textarea you just put it after the first tag and before the close tag. How can I do it with this? Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/ Share on other sites More sharing options...
.josh Posted June 5, 2006 Share Posted June 5, 2006 [code]$months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');$query = mysql_query("select * FROM table WHERE id='$id'");$row = mysql_fetch_array($query);echo "<select name='month'>";foreach ($months as $val) { echo "<option value='$val'"; if ($val==$row['month']) { echo " selected"; } echo ">".$val;}echo "</select>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-41955 Share on other sites More sharing options...
yarub Posted June 6, 2006 Author Share Posted June 6, 2006 Perfect. Thank you very much. Got another question. I'm now trying to do it with a radio button, but I'm trying to do it a bit differently. Here's basically what I want it to look like...O YesO NoYes is what displays to the person, but I want "true" to be the value. For no, I want "false" to be the value. Are you able to do that as well? Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42309 Share on other sites More sharing options...
.josh Posted June 6, 2006 Share Posted June 6, 2006 i don't understand how this ties into the months of the year, can you explain some more? Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42311 Share on other sites More sharing options...
yarub Posted June 6, 2006 Author Share Posted June 6, 2006 Well, the months and years thing has been solved. I got that working. Now I'm working with something else. I'm just using a forum where yes sends a value of true and no sends a value of false. However, I'm having problems getting it to work right as I can't get it to pull the current value that is set and be able to submit a new value if it's changed. Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42314 Share on other sites More sharing options...
.josh Posted June 6, 2006 Share Posted June 6, 2006 well, in your form, you would have your radio buttons:[code]<form action='blah.php' method='post'> <input type="radio" name='yesorno' value='true'>yes <input type="radio" name='yesorno' value='false'>no <input type="submit"></form>[/code]notice how both radio buttons have the same name, but different values. when you click the submit button, it goes to blah.php and you now have the variable $_POST['yesorno'] to play with[code]//blah.phpif($_POST['yesorno']) { echo "value of yesorno is: ". $_POST['yesorno'];}[/code]if you selected the yes radio button, it will display[b]value of yesorno is: true[/b]if you selected the no radio button, it will display[b]value of yesorno is: false[/b] Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42504 Share on other sites More sharing options...
yarub Posted June 7, 2006 Author Share Posted June 7, 2006 That part I understand. I'm asking how to do it the same way as the select form. I want to display it so that I can edit it at the same time if I need to. I want to make it so I can pull what the user has from the database into an administration panel, and be able to keep it as YES/NO or change it to YES/NO and then submit it. Does that make sense? Like the way you did it with the select one. Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42651 Share on other sites More sharing options...
.josh Posted June 7, 2006 Share Posted June 7, 2006 well, here's one way to do it....[code]$query = mysql_query("select * FROM table WHERE id='$id'");$row = mysql_fetch_array($query);//assuming that the column that holds the true/false value is called 'boolval'if ($row['boolval']=='true') { $truechecked = " checked"; $falsechecked = "";} else { $falsechecked = " checked"; $truechecked = "";}//<form ...> echo"<input type='radio' name='yesorno' value='true' $truechecked>yes"; echo"<input type="radio" name='yesorno' value='false' $falsechecked>no";//</form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42661 Share on other sites More sharing options...
yarub Posted June 7, 2006 Author Share Posted June 7, 2006 Awesome! It worked! Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/11213-mysql-forms-and-the-select-form-option/#findComment-42699 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.