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
https://forums.phpfreaks.com/topic/179120-output-sql-using-html-label-tag/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.