Question

I'm trying to check a checkbox based on its database value, i have tried the following but no joy, any suggestions?

I am using Kohana framework.

public static function defaultdistance(){
    $result = DB::select('value')->from('mytable')->where('key', '=', 'default-distance')->execute();
    $distancestores = $result->as_array();
    foreach($distancestores as $distancestore)
    {
        echo 'Value: '.$distancestore['value'];
    }
}   

<label class="shortLabel"><input type="radio" name="distance" value="10" <?php if ($distancestore['value'] == '10') echo "checked='checked'"; ?> /> 10 <?php echo $dict->transl('distance_km'); ?></label>
<label>&nbsp;</label><label class="shortLabel"><input type="radio" name="distance" value="15" <?php if ($distancestore['value'] == '15') echo "checked='checked'"; ?> /> 15 <?php echo $dict->transl('distance_km'); ?></label>

No correct solution

OTHER TIPS

May be you need like this

$distancestores = $result->as_array();
foreach($distancestores as $distancestore)
{
    ?> 
    <label class="shortLabel">
          <input type="radio" name="distance" value="10" 
         <?php if ($distancestore['value'] == '10') echo "checked='checked'"; ?> /> 
         10 <?php echo $dict->transl('distance_km'); ?> 
    </label>
    <?php 
} 

try this i think you have to use ternary operator to resolve this issue.

<input type="radio" name="distance" value="10"
    <?php $select = $distancestore['value']=='10'?'checked':'';
    echo $select; ?>
     10 <?php echo $dict->transl('distance_km'); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top