cougarreddy Posted August 5, 2009 Share Posted August 5, 2009 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 More sharing options...
Hybride Posted August 5, 2009 Share Posted August 5, 2009 Try a switch/case statement. Link to comment https://forums.phpfreaks.com/topic/168956-display-radio-selected/#findComment-891405 Share on other sites More sharing options...
cougarreddy Posted August 5, 2009 Author Share Posted August 5, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/168956-display-radio-selected/#findComment-891408 Share on other sites More sharing options...
cougarreddy Posted August 5, 2009 Author Share Posted August 5, 2009 @Hybride, thanks for the help, that simple solution didn't cross my mind .. anyway, I have one more problem, just like the radio button, there are 10 check boxes to be displayed with the present values checked, can u help me how to do that? Link to comment https://forums.phpfreaks.com/topic/168956-display-radio-selected/#findComment-891419 Share on other sites More sharing options...
cougarreddy Posted August 5, 2009 Author Share Posted August 5, 2009 any help? Link to comment https://forums.phpfreaks.com/topic/168956-display-radio-selected/#findComment-891512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.