PHP mysqli遍历表字段名和值


header('Content-Type:text/html;Charset=utf-8');
$db = new mysqli();
$db->connect('localhost','root',12345,'test');
$sql='select * from category';
$query=$db->query($sql);


while($rs=mysqli_fetch_array($query)){
    $result[]=$rs;
}
$i=0;
print_r($result);
echo '
'
; foreach($result as $key=>$value){ $i+=1; if($i%2==0){ echo $key.' '; echo $value.'
'
; } } $query->free(); $db->close();

你可能感兴趣的:(php)