php读取数据库数组 php从数据库中读取数据

PHP 用数组读取数据库的问题$sql
=
"select
class
from
name
where
Id
=
1";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
mysql_free_result($res);
$arr=explode(',',$row['name']);
print_r($arr);
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 = https://www.04ip.com/post/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如何获取数据库信息代码如下:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"table
width=572
height=56
cellspacing=1
";
//创建html表格
echo
"tr
bgcolor=#9999FF";
echo
"th
width=33
scope=colid/th";
echo
"th
width=100
scope=coluser_name/th
";
echo
"th
width=100
scope=coluser_pass/th
";
echo
"th
width=100
scope=colstaus/th";
echo
"th
width=100
scope=colinsert_time/th";
echo
"/tr";
$SQL
=
"select
*
from
user_info";
$query
=
mysql_query($SQL);
//SQL查询语句
while
($row
=
mysql_fetch_array($query)){
//使用while循环mysql_fetch_array()并将数据返回数组
echo
"tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC";
echo
"td$row[0]/td";
//输出数组中数据
echo
"td$row[1]/td";
echo
"td$row[2]/td";
echo
"td$row[3]/td";
echo
"td$row[4]/td";
echo
"/tr";
}
echo
"/table";输出记录截图
【php读取数据库数组 php从数据库中读取数据】php读取数据库数组的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php从数据库中读取数据、php读取数据库数组的信息别忘了在本站进行查找喔 。

    推荐阅读