【问题标题】:want to edit the checkbox values in edit.php page想要编辑edit.php页面中的复选框值
【发布时间】:2014-07-31 19:56:31
【问题描述】:

我想编辑复选框值....我在 php 中创建了一个编辑页面。但是选定的值(从入口页面输入)没有显示并且无法更新值......那些输入的值不会被带到编辑页面,但是所有其他文本输入的值都会被相应地采用。

.......编辑页面>>

<tr>
    <td align='center'>select gots-:</td>
    <td>
        <input type="checkbox" name="p_option[]" value="withcupon" <?php if(in_array($result->p_option=='withcupon','')) { ?> checked="checked"
        <?php } ?>>with cupon
        <br>
        <input type="checkbox" name="p_option[]" value="withdiscount" <?php if(in_array($result->p_option=='withdiscount','')) { ?> checked="checked"
        <?php } ?>>with discount
        <br>
        <input type="checkbox" name="p_option[]" value="aschannelpartner" <?php if(in_array($result->p_option=='aschannelpartner','')) { ?> checked="checked"
        <?php } ?>>as channel partner
        <br>
        <input type="checkbox" name="p_option[]" value="freepasses" <?php if(in_array($result->p_option=='freepasses','')) { ?> checked="checked"
        <?php } ?>>free passes
        <br>
        <input type="checkbox" name="p_option[]" value="vendorcontacts" <?php if(in_array($result->p_option=='vendorcontacts','')) { ?> checked="checked"
        <?php } ?>>vendor contacts
        <br>
        <input type="checkbox" name="p_option[]" value="reatilersaddresses" <?php if(in_array($result->p_option=='reatilersaddresses','')) { ?> checked="checked"
        <?php } ?>>reatilers addresses
        <br>
    </td>
</tr>

【问题讨论】:

  • 我不得不用谷歌搜索,但你的 in_array 命令不正确,应该是 if(in_array('withcupon',$result->p_option))....
  • 实际上是在 in_array 命令的第一个参数内进行比较,而不是在 in_array('what you looking for','in the array)
  • yap 该函数至少需要两个参数......但是我忘记在更新页面中定义提到的变量

标签: php checkbox edit


【解决方案1】:

假设 $result->p_option 是一个数组,你应该替换:

... if(in_array($result->p_option=='freepasses','')) ...

为:

... if(in_array('freepasses',$result->p_option)) ...

(以及所有其他“如果”...)

【讨论】:

  • 但另一件事是用逗号操作符取值....我想作为一个数组来显示所选字段
  • 你可以爆炸(",",$string)
猜你喜欢
  • 2018-11-17
  • 1970-01-01
  • 2015-03-11
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多