在封装MySQL类里面写个getAll函数 和query函数
public function getAll($sql)
{
$rs =$this->query($sql);
$list =array();
if(!$rs)
{
return false;
}
else{
while($row = mysql_fetch_assoc($rs))
{
$list[]=$row;
}
return $list;
}
}
public function query($sql)
{
return mysql_query($sql,$this->conn) ; //$this->conn是连接数据库的资源变量
}
在类的外面初始化一个对象,然后写三个sql语句获取三个列,把sql语句通过getAll函数发出去获得结果,最后查询结果自己再写个数组放进去。。。封装类的内容太多就不写了,不知道能不能帮到楼主- -
$array=array( array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size1'), array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size2'), array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size1'), array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size2'), array('CKMC'=>'store2','GG1MC'=>'color1','GG2MC'=>'size1'), array('CKMC'=>'store2','GG1MC'=>'color2','GG2MC'=>'size2'),);$array2=array();foreach($array as $val){ if(array_key_exists($val['CKMC'],$array2)) { if(array_key_exists($val['GG1MC'],$array2[$val['CKMC']])) { $array2[$val['CKMC']][$val['GG1MC']][]=$val; } else $array2[$val['CKMC']][$val['GG1MC']]=array($val); } else $array2[$val['CKMC']]=array($val['GG1MC']=>array($val));}echo '<pre class="brush:php;toolbar:false">';print_r($array2);echo '