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 读取数据库数组。。。

假如 数据为 $value

$temp=explode(“,”,$value);  

foreach($temp as $v){

   $result[$v]=1;

}

然掘简后html的时判侍裤候可以这样:

if($result[‘admin’]){

   谈让echo ‘input type=checkbox /’;

}

同理其他类型,可以foreach 输出

关于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”;

}

?