php怎么把数据写进数组 php如何输出数组

PHP 去读数据库到数组 怎么弄

本文实例讲述了php实现通用的从数据库表读取数据到数组的函数。分享给大家供大家参考。具体分析如下:

创新互联是一家专注于成都网站设计、网站建设、外贸网站建设与策划设计,静安网站建设哪家好?创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:静安等地区。静安做网站价格咨询:18982081108

此函数不关心表结构,只需要指定表名、结构和查询条件既可以对表进行通用查询操作,非常实用。

function listmytablerows($table, $name, $field, $where, $textID) { / / Connect to the database and query execution connect (); $Sql = "select * from". $table. "". $where. "ORDER BY". $field; $Req = mysql_query($sql); $Res = mysql_num_rows($req); ? Select name = "?php echo $name; ?" id="?php echo $textID; ?" option value="" ____/ option ? Php / / We do a loop that will read the information for each record while ($data = mysql_fetch_array($res)) { / / We display the information from the current record ? Option value = "?php echo $data['id']; ?" ?php echo $data[$field]; ? / Option ? Php } ? / Select ? Php } ?

php怎么写入、存储数组数据?

PHP有自带的高性能函数 var_export

conn.php

?php

$dbconfig = array (

'host'='127.0.0.1',

'name'='root',

'password'='123456',

?

b.php

?php

// 读取配置

include 'conn.php';

echo $dbconfig['host'];

// 修改配置

$dbconfig['host'] = 'xxx.xxx.xxx.xxx';

file_put_contents('conn.php', "?php\n$dbconfig = " . var_export($dbconfig) . "\n?");

// 再读取配置

include 'conn.php';

echo $dbconfig['host'];

?

参考连接:

php从数据库取出的数据如何写入一个新的数组

数据库提到的数据一般是资源类型的,要逐一读出,添加到数组

while($row = mysql_fetch_assoc($res)){

$data[] = $row;

}

如何把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如何输出数组
分享URL:http://csdahua.cn/article/hhoiig.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流