【发布时间】:2021-08-03 15:21:21
【问题描述】:
您好,我正在处理多个复选框,并且复选框的值以这种格式存储在我的数据库 2、3、4
我的刀片文件的代码:-
<table class="table table-striped">
@foreach($var as $vars)
<tbody>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 1 ? 'checked' : '')}}>Cold/Hot Forging
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 2 ? 'checked' : '')}}>Injection Molding
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 3 ? 'checked' : '')}}>Precision Machining
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 4 ? 'checked' : '')}}>Sheet Metal Pressing
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 5 ? 'checked' : '')}}>Sub-assembly
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 6 ? 'checked' : '')}}>Surface tretment
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="larger" name="process[]" value="" {{ ($vars->process == 7 ? 'checked' : '')}}> Other
</td>
</tr>
</tbody>
@endforeach
</table>
所以这段代码只显示了一个选中的复选框,其值为 2 控制器代码:-
$processvalue = ProcessValue::where('company_basic_info_id','=',$id)->get();
【问题讨论】:
-
您存储的是逗号分隔的值字符串 (
2,3,4)? -
如果
$vars->process = '1,2,3',这将永远不会是真的$vars->process == 1。
标签: javascript php mysql ajax laravel