pro_se Posted September 2, 2006 Share Posted September 2, 2006 Hey All! I am having a problem with using radio buttons to change an integer in a mysql database... The values they need to have are 'y' and 'n'. And when someone opens a page it gets the information from the database and it sets the default selection for the radio button as what is in the database (y or n). any suggestions? Quote Link to comment Share on other sites More sharing options...
pro_se Posted September 2, 2006 Author Share Posted September 2, 2006 wow... maybe it could use ajax... anyone? Quote Link to comment Share on other sites More sharing options...
corbin Posted September 2, 2006 Share Posted September 2, 2006 Or you could just pull it from the database thru mysql queries and echo it into the appriate radio button or what ever... Quote Link to comment Share on other sites More sharing options...
pro_se Posted September 2, 2006 Author Share Posted September 2, 2006 can u give me and example of what that may look like? this is what i am currently using (ghetto status): [code]<input name="showgeneral" type="text" id="showgeneral" value="<?php $username = $_SESSION['username'];$result = mysql_query("SELECT * FROM users WHERE username='$username'");while($r=mysql_fetch_array($result)){ $showgeneral=$r["showgeneral"]; echo "$showgeneral";}?>" size="2" maxlength="1"> [/code] Quote Link to comment Share on other sites More sharing options...
pro_se Posted September 2, 2006 Author Share Posted September 2, 2006 but i want a radio button instead... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 2, 2006 Share Posted September 2, 2006 You need to get the value from the database before you create the input statements, so you can determine which button is presented as being checked:[code]<?php$username = $_SESSION['username'];$result = mysql_query("SELECT * FROM users WHERE username='$username'");while($r=mysql_fetch_assoc($result)) { $no_sel = ($r['showgeneral'] == 'n')?'checked':''; $yes_sel = ($['showgeneral'] == 'y')?'checked':''; echo 'Yes: <input name="showgeneral" type="radio" id="showgeneral_yes" value="y" ' . $yes_sel . '><br>'; echo 'No: <input name="showgeneral" type="radio" id="showgeneral_no" value="n" ' . $no_sel . '><br>';}?>[/code]Note: This code hasn't been checked for syntax errors...Ken Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 2, 2006 Share Posted September 2, 2006 [code]$yes_sel = ($['showgeneral'] == 'y')?'checked':'';[/code]needs ot be[code]$yes_sel = ($r['showgeneral'] == 'y')?'checked':'';[/code]just noticed the syntax colors were diffrent :)Liam Quote Link to comment Share on other sites More sharing options...
pro_se Posted September 2, 2006 Author Share Posted September 2, 2006 it does not display correctly... Quote Link to comment 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.