
正文
php读取数据到数组 php获取数据
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
关于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";
}
?
相关问答
Q1: 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]['字段名称'];
?
Q2: PHP 读取数据库数组。。。
假如 数据为 $value
$temp=explode(",",$value);
foreach($temp as $v){
$result[$v]=1;
}
然后html的时候可以这样:
if($result['admin']){
echo 'input type=checkbox /';
}
同理其他类型,可以foreach 输出
Q3: PHP 去读数据库到数组 怎么弄
本文实例讲述了php实现通用php读取数据到数组的从数据库表读取数据到数组php读取数据到数组的函数。分享给大家供大家参考。具体分析如下php读取数据到数组:
此函数不关心表结构php读取数据到数组,只需要指定表名、结构和查询条件既可以对表进行通用查询操作php读取数据到数组,非常实用。
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获取数据的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。





