各位好,我知道写入是这样,复选框的名臣命为shareAn[]
然后
$chek=$_POST[shareAn];
for($i=0;$i<count($chek);$i++)
{
$shareAn[]=$chek[$i];
}
$str1=implode(",",$shareAn);后
再insert写$str1就行,那如果要修改前,如何正确显示出数据表字段中复选框的值呢?
谢谢
然后
$chek=$_POST[shareAn];
for($i=0;$i<count($chek);$i++)
{
$shareAn[]=$chek[$i];
}
$str1=implode(",",$shareAn);后
再insert写$str1就行,那如果要修改前,如何正确显示出数据表字段中复选框的值呢?
谢谢
然后explode后 遍历数组
如果字段中的值为a,b,c,d,那在修改页面如何能正确显示出这些值呢?怎么一一对应?
<input type="checkbox" name="shareAn[]" value="a" />
<input type="checkbox" name="shareAn[]" value="b" />
<input type="checkbox" name="shareAn[]" value="c" />
<input type="checkbox" name="shareAn[]" value="d" />
关键是那个selected要如何判断出来?
谢谢
<input type="checkbox" name="shareAn[2][]" value="b" />
<input type="checkbox" name="shareAn[3][]" value="c" />
<input type="checkbox" name="shareAn[4][]" value="d" />
这样你就可以知道,3=C 2=b
<input type="checkbox" name="shareAn[]" value="a" checked />
<input type="checkbox" name="shareAn[]" value="b" />
<input type="checkbox" name="shareAn[]" value="c" />
<input type="checkbox" name="shareAn[]" value="d" />
关键是那个checked要如何才能正确判断出来?
<input name="shareAn[]" type="checkbox" value="a" <?php
$sql="select * from products where ID='".$_GET['ProID']."'";
$result=mysql_query($sql,$conn);
$rs=mysql_fetch_array($result);
$ss=explode(',',$rs['shareAn']);
for ($i=0;$i<count($ss8);$i++){
if ($ss['0']=="a") echo "checked";
}
?>>a
这个不行...
得到的结果是什么?
print_r($rs);
print_r($rs);这个结果你可能看得不清楚,太多字段...
a,b,c [shareAn] => a,b,c [28]还有其他.<input name="shareAn[]" type="checkbox" value="b" <?php
$sql="select * from products where ID='".$_GET['ProID']."'";
$result=mysql_query($sql,$conn);
$rs=mysql_fetch_array($result);
$ss=explode(',',$rs['shareAn']);
for ($i=0;$i<count($ss);$i++){
if ($ss['1']=="b") echo "checked";
}
?>>b
这个还是有问题,请问这个写法错在哪里?
如果循环有问题,看看$ss=explode(',',$rs['shareAn']);
看看你的$rs['shareAn']是什么值。