drc4925 2016-09-27 07:08
浏览 56


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


foreach($post_id as $data){

<?php var_dump($d);?>
<?php var_dump($f);?>
<form method="post" action="<?php echo site_url('Student_info/update'); ?>">
<td>ENTER NAME</td>
<td><input type="text" name="name" value="<?php echo $b;   ?>"></td>
<td>ENTER EMAIL </td>
<td><input type="email" name="email" value="<?php echo $c; ?>"></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> <textarea name="notes" rows="4" cols="50"><?php echo $e; ?></textarea> </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>
<td><input type="submit" name="add" value="submit"/></td>    
  • 写回答

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国际化