Jump to content

output sql using html label tag?


nashsaint

Recommended Posts

Hi,

 

This is what I am trying to accomplish:

[] Male

[] Female

 

Simple tick boxes populated from sql but i just don't know how to do it. 

I have the sql query and thinking of outputting it this way:

 

<form>
  <label for="maleID">malefromsql</label>
  <input type="radio" name="sex" id="maleID" />
  <br />
  <label for="femaleID">femalefromsql</label>
  <input type="radio" name="sex" id="femaleID" />
</form>

 

but i dont know how to pass the sql query result to a variable and finally output it .

 

Any help is appreciated greatly. thanks.

Link to comment
Share on other sites

Something like..

 

$result = mysql_query("SELECT gender FROM table");
$row = mysql_fetch_assoc($result);

<form>
  <label for="maleID">malefromsql</label>
  <input type="radio" name="sex" id="maleID" <?php if($row['gender'] == 'Male') { echo 'selected="selected"'; } ?> />
  <br />
  <label for="femaleID">femalefromsql</label>
  <input type="radio" name="sex" id="femaleID" <?php if($row['gender'] == 'Female') { echo 'selected="selected"'; } ?> />
</form>

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.