
正文
php获得的数据装进数组 php获得的数据装进数组里
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php从数据库取出的数据如何写入一个新的数组
数据库提到的数据一般是资源类型的,要逐一读出,添加到数组
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}
相关问答
Q1: 关于php获取数据库的内容存为数组的问题
php查询mysql数据库并将结果保存到数组的方法。具体分析如下:
主要用到了mysql_fetch_assoc函数
mysql_fetch_assoc语法如下:
?
1
array mysql_fetch_assoc (resource $Result_Set)
范例代码如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
?php
$UserName = 'abc';
$Password = '1234';
$DbHandle = mysql_connect ('localhost', $UserName, $Password);
if (!$DbHandle) {
die 'No database connection could be established.';
}
$DBName = 'w3db;
if (!mysql_select_db ($DBName, $DbHandle)) {
die 'Database could not be selected.';
}
$Query = "SELECT ISBN, Title, Author FROM articles";
$articles = mysql_query ($Query, $DbHandle));
while ($Row = mysql_fetch_assoc ($articles)) {
echo "ISBN = $Row['ISBN']br /\n";
echo "Title = $Row['Title']br /\n";
echo "Author = $Row['Author']br /\n";
}
?
Q2: php接收到html数据后怎样存储到数组?
$_POST本身就是一个数组,如果电话字段要以数组的方式传递,有两种方法:
1、表单上内容input type="text" id="phone" name="phone"
可以改为input type="text" id="phone" name="phone[]"
2、$phone=$_POST['phone'];下面加一句将字符串围为数组
$phones=array($phone);
Q3: 如何把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]['字段名称'];
?
Q4: PHP怎样把得到的数据的值保存在一个数组里面
input 存在着2个方式 get 和post php获得的数据装进数组,你可以根据你的需求去选择。
现在很多框架都支持直接将post或者get到的数据作为整个数组保存哈
$input_array = $_GET['paramsName'];
参考链接php获得的数据装进数组:
关于php获得的数据装进数组和php获得的数据装进数组里的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







