关于php获取数据库的内容存为数组的问题
假如表名demo假如内容为iduserpassword111222--------------------我想取出格式为返回结果是二维数组,带下标。一行为一个下标...
假如表名demo
假如内容为
id user password
1 1 1
2 2 2
--------------------
我想取出格式为
返回结果是二维数组,带下标。一行为一个下标 展开
假如内容为
id user password
1 1 1
2 2 2
--------------------
我想取出格式为
返回结果是二维数组,带下标。一行为一个下标 展开
展开全部
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";
}
?>
主要用到了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";
}
?>
追问
.......哥啊,这都快3年了。我也是醉了。有点意思 0.0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询