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 如何输入百度,显示本地下载的html文件页面,地址栏还显示百度的地址
  • ¥15 通过kinect制作换装程序但是服装不贴合(标签-ar)
  • ¥20 matlab如何绘制三维瀑布图
  • ¥15 关于用abap来解决动态规划的问题,但是要求输出索引值,这个是难点
  • ¥15 在ISIS中什么是IP从地址
  • ¥15 压测时,并发量过高时,响应时间出现尖刺
  • ¥15 关于vmprotect3.8.4虚拟文件一项
  • ¥15 在不用IT调试的情况下怎样能连外网
  • ¥20 C#调用虚拟键盘TabTip.exe
  • ¥15 Qt4代码实现下面的界面