function get_usercartype(){
global $DB;
$memberlist = $DB->fetch_one_array("select * from `partner` where `username` = '$username' ");
$arr = $memberlist['other'];
$typelist = explode("|",$arr);//从用户表中获取到选择车型的数组(有值)
//zu lin che xing
$carlist = $DB->getall("select * from `car_type`");//车型表
foreach ($carlist as $car){
$cartype[] = $car['type'];
}
foreach ($cartype as $key=>$val){
// debug($cartype[$key]);
// debug($typelist[$key]);
$str = '<td width="30" height="23" align="center" valign="middle"><input type="checkbox" name="type[]" id="type[]" value='.$cartype[$key];
if( in_array($typelist[$key],$cartype))$str .=' checked = "checked"';
$str .= ">".$cartype[$key]."</td>";
debug($str); 
}
}
//结果是哪个也没选中 那位高手给指点下

解决方案 »

  1.   

    if( in_array($typelist[$key],$cartype))$str .=' checked = "checked"';中的
    $typelist = explode("|",$arr);//从用户表中获取到选择车型的数组(有值)
    $cartype[] = $car['type']; //从数据库得到的数组
    foreach ($cartype as $key=>$val){//这个 $key 是 $cartype 的下标,能和 $typelist 的下标对应吗?正确的写法是
    if( in_array($val,$typelist))$str .=' checked = "checked"';

    if( in_array($cartype[$key],$typelist))$str .=' checked = "checked"';