drc4925 2016-09-27 07:08
浏览 56
已采纳

如何将复选框值带到codeigniter中更新页面

Actually i fetched data successfully but checkbox is not showing checked values. Maybe the logic is wrong. And it is necessary to use foreach here, can't we direct echo in value field, i am new to it and maybe the mistakes are silly

view

<html>
<?php
foreach($post_id as $data){

     $a=$data->id;
     $b=$data->name;
     $c=$data->email;
     $d=json_decode($data->skills);
     $e=$data->notes;
     $f=$data->gender;
}
?>
<?php var_dump($d);?>
<?php var_dump($f);?>
<body>
<form method="post" action="<?php echo site_url('Student_info/update'); ?>">
<table>
<tr>
<td>ENTER NAME</td>
<td><input type="text" name="name" value="<?php echo $b;   ?>"></td>
</tr>
<tr>
<td>ENTER EMAIL </td>
<td><input type="email" name="email" value="<?php echo $c; ?>"></td>
</tr>
<tr>
<td>ENTER SKILLS</td>
<td>
<input type="checkbox" name="skills[]" value="php" <?php if($d == "php"){echo 'checked="checked"'; } ?>>php<br>
<input type="checkbox" name="skills[]" value="dotnet" <?php if($d == "dotnet"){echo 'checked="checked"'; } ?> >dotnet<br>
<input type="checkbox" name="skills[]" value="java" <?php if($d == "java"){echo 'checked="checked"'; } ?>>java<br>
<input type="checkbox" name="skills[]" value="ruby_on_rails" <?php if($d == "ruby_on_rails"){echo 'checked="checked"'; } ?> >ruby_on_rails<br>
</td>
</tr>
<tr>
<td>NOTES</td>
<td> <textarea name="notes" rows="4" cols="50"><?php echo $e; ?></textarea> </td>
</tr>
<tr>
<td>GENDER</td>
<td> <input type="radio" name="gender" value="male" <?php if($f == "male"){echo 'selected="selected"'; } ?>> Male<br>
     <input type="radio" name="gender" value="female" <?php if($f == "Female"){echo 'selected="selected"'; } ?>> Female<br> </td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="add" value="submit"/></td>    
</tr>  
</table>
</form>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • duanla3319 2016-09-27 07:32
    关注

    Result of this $d is an object not a string value because you are using json_decode() here:

    $d=json_decode($data->skills); // this will produce an object
    

    You can use in_array(), but for this you need to use second param as TRUE in json_decode() function, this will return the result in array, something like:

    $d=json_decode($data->skills,TRUE); // this will return an array
    

    Than you can check like that:

    <input type="checkbox" name="skills[]" value="php" <?=(in_array("php",$d) ? 'checked=""' : '')?>>php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化