php查询数据放数组 php检查数组中是否存在某个值

如何把php 查询结果存入数组遍历数据表,把相应的数据放到数组中即可
例如:
?php
//定义一个数组,用于保存读取到的数据
$contents
=
array();
$query
=
mysql_query("select
*
from
table");
//遍历数据表
while($array
=
mysql_fetch_array($query)){
$contents[]
=
$array;
}
print_r($contents);
//然后循环数组,或者通过键名使用数组
foreach($contents
as
$value){
print_r($value);
}
echo
$contents[0]['字段名称'];
?
php如何把多条查询结果放在数组中,?php
//引入外部数据库连接文件
include("conn.php");
//要查询的sql语句数组
$sql[0]=mysql_query("select *from kongqizhiliang order by id desclimit 1");
$sql[1]=mysql_query("select *from beidian order by id desclimit 1");
$sql[2]=mysql_query("select *from beidian order by id desclimit 1");
//遍历结果
foreach ($sql as $key = $value) {
while($row=mysql_fetch_assoc($value)){
$data[]=$row;
}
$output[]=$data;
}
print(json_encode($output));
mysql_close();
?
想把php查到的mysql数据输出在一个数组里首先定义一个数组 , 然后遍历数据表,把相应的数据放到数组中,最后通过json_encode()转化数组
json_encode() 函数的功能是将数值转换成json数据存储格式 。
例如:
【php查询数据放数组 php检查数组中是否存在某个值】关于php查询数据放数组和php检查数组中是否存在某个值的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读