princeofpersia Posted January 9, 2011 Share Posted January 9, 2011 Hi guys, im having a radio button which i need it to be checked if its status is equal to something. as an example i need to use the checkbox below checked if its field in mysql is equal to male <p>Male <input type="radio" name="male" value="Male"/> <br/> this is made for a profile page where users can insert their gneder, I know i have to return the value from myslq to check if its equal to radio button value, I can do select mysql_query from my db but how should i say if its match, check the radio button? can u please help me how to do it? Quote Link to comment Share on other sites More sharing options...
nderevj Posted January 10, 2011 Share Posted January 10, 2011 One way to do it is to have PHP generate the HTML for each of the radio buttons. As it generates each of the buttons it would check the database to determine if the person is Male or Female. Based on this info, it would generate a "checked" button that contains the attribute: checked="checked". For example (pseudocode): $profiles = ... // Assume you retrieved all of your profiles as a collection of objects from your database foreach($profiles as $profile) { if($profile->gender == 'male') { echo '<input type="radio" name="male" value="Male" checked="checked" />'; echo '<input type="radio" name="female" value="Female" />'; } else { echo '<input type="radio" name="male" value="Male" />'; echo '<input type="radio" name="female" value="Female" checked="checked" />'; } } Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted January 10, 2011 Author Share Posted January 10, 2011 thanks, ill give it a try 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.