Jump to content

display radio selected


cougarreddy

Recommended Posts

i have "edit user details" page, where I need to display the existing values. user can be either student or employee. I have the following code to display what is the current role of the user. I want to know if there is any shorter code to do this than this lengthy code.. lengthy because, I may extend the roles to be 5, 6 diff types. so while displaying it, i need to write 6 different if statements, which is ridiculous I think,

 

<?php 
        if($role=='Employee')//$role is collected from db in PHP code before starting the html output.
{
      echo "<input type='radio' name='group1' value='Employee' checked>Employee";
      echo "<input type='radio' name='group1' value='Student'>Student";
}
else
{
     echo "<input type='radio' name='group1' value='Employee'>Employee";
     echo "<input type='radio' name='group1' value='Student' checked>Student";
}

?>

 

thanks in adv

Link to comment
https://forums.phpfreaks.com/topic/168956-display-radio-selected/
Share on other sites

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.