I need a way so that we can show selected option in list box without using if condition in loop since some times we have lot of options and we have too much if conditions to check.
| SitePoint Sponsor |
I need a way so that we can show selected option in list box without using if condition in loop since some times we have lot of options and we have too much if conditions to check.
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
I am not sure whether it is possible to make an option selected in the list box without using if or any other types of conditional statements in PHP. But if you have taken the options from the database table or from any of the arrays, then you don't have to make any more than one if statement for selection.
If possible to do so without using conditions, it would be helpful to me too.
Thanks.
still waiting for a solution
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
Could you post your array or data to be shown in the list box? So that we could discuss here further clearly. But i dont think that you can do it without using any type of conditions. From where you data comes for populating the list?




Why can't you do this:
PHP Code:$selected = isset($_POST['posted_value']) ? $_POST['posted_value'] : 'default';
foreach ($options as $option)
{
print '<option value="'.$option.'"';
if ($option == $selected) print ' selected="selected"';
print '>' . $option . '</option>';
}
Finally found a way:
I set the particular array index that is my selected value with value "selected" and repeated that array for all option values, when i reached that value it added "selected" in that option.
Thanks for your all supportCode:<select name="isalutation_id" > <? $salutations = Get_Details($obj,'salutation_mast','','isalutation_id'); $selArrVal[$row[0]['isalutation_id']] = "selected"; for($i=0;$i<count($salutations);$i++){ ?><option value="<?=$salutations[$i]['isalutation_id']?>" <?=$selArrVal[$salutations[$i]['isalutation_id']]?> ><?=$salutations[$i]['vsalutation']?></option><? } ?> </select>![]()
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
Bookmarks