Jump to content

checkbox selected question


princeofpersia

Recommended Posts

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?

Link to comment
Share on other sites

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" />';
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.