您的位置:首页 > 数据库 > MySQL

mysqli:循环数据显示到页面

2011-11-14 20:49 183 查看
mysqli:循环数据显示到页面

连接数据库smarty_fenye 数据表tbl_product

mysqli-----连接对象

mysqli_result----select结果集对象

mysqli_stmt----预处理对象

一:连接数据库mysqli

$mysqli=new mysqli(“localhost”,”root”,”123”,”smarty_fenye”);

二:发送多条语句

$sql=”set names gbk;select * from tbl_product;select name price tbl_product”;

三:循环显示

if($mysqli->multi_query($sql)){

do{

if($result=$mysqli->store_result()){

while($row=$result->fetch_row()){

foreach($row as $value){

echo $value."<br>";

}

}

echo "<br>";

//返回总行数

echo "总行数:".$result->num_rows;

echo "<br>";

echo "总列数:".$result->field_count;

echo "<br>";

echo $result->current_field."当前列";

echo "<br>";

@ $result->field_seek(1);

echo $result->current_field."当前列";

echo "<br>";

$a=$result->fetch_field();

echo "名称1:".$a->name;

echo "<br>";

@ $result->field_seek(2);

echo $result->current_field."当前列";

echo "<br>";

$b=$result->fetch_field();

echo "名称2:".$b->name;

echo "<br>";

}

}while($mysqli->next_result());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: