示例如下:
$con
=mysql_connect(
'localhost'
,
'root'
,
''
);
//数据库信息
mysql_select_db(
'shop'
);
//数据库名
mysql_query(
"set names utf8"
);
//设置字符集编码
$sql
=
"select goods_name,goods_number,shop_price from goods"
;
//查询语句
$res
=mysql_query(
$sql
);
//执行查询
while
(
$row
=mysql_fetch_assoc(
$res
)){
$rows
[]=
$row
;
//接受结果集
}
//遍历数组
foreach
(
$rows
as
$key
=>
$v
){
echo
$v
[
'goods_name'
].
"---"
.
$v
[
'goods_number'
].
"---"
.
$v
[
'shop_price'
].
""
;
}