这是PHP获取数据库信息的代码 希望能给你带来启发
php
$conn=mysql_connect("localhost","root","");
$select=mysql_select_db("books",$conn);
$query="insert into computers(name,price,publish_data) ";
$query="select * from computers";
$result=mysql_query($query);
//以下是使用mysql_result()函数来获取到查询结果
$num=mysql_num_rows($result);
for($rows_count=0;$rows_count$num;$rows_count++){
echo "书名:".mysql_result($result,$rows_count,"name");
echo "价格:".mysql_result($result,$rows_count,"price");
echo "出版日期:".mysql_result($result,$rows_count,"publish_data")."br";
}
//以下是使用mysql_fetch_row()函数来获取到查询结果
while($row=mysql_fetch_row($result))
{
echo "书号:".$row[0]."br";
echo "书名:".$row[1]."br";
echo "br";
//以下是使用mysql_fetch_array()函数来获取到查询结果
while($row=mysql_fetch_array($result))
echo "价格:".$row["price"]."br";
echo "出版日期:".$row["publish_data"]."br";
//以下是使用mysql_fetch_object()函数来获取到查询结果
while($row=mysql_fetch_object($result))
echo "书号:".$row-id."br";
echo "书名:".$row-name."br";
echo "价格:".$row-price."br";
echo "出版日期:".$row-publish_data."br";
试编写代码如下:
//从数据库根据?id?获取颜色
function?getColor($db,?$id)
if?($result?=?$db-query("SELECT?*?FROM?color?where?id='"?.?$id?.?"'"))
$row?=?$result-fetch_assoc();
return?$row['color'];
return?'#000000';
$mysqli?=?new?mysqli("localhost",?"test",?"test",?"room");
if?($mysqli-connect_error)?{
printf("数据库连接错误:?%s\n",?mysqli_connect_error());
exit();
table?border="1"?cellspacing="0"
tr
td?bgcolor="?php?echo?getColor($mysqli,'1')?"1/td
/tr
/table
$mysqli-close();
代码如下:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"table
border=0
cellspacing=1
";
//创建html表格
"tr
"th
scope=colid/th";
width=100
scope=coluser_name/th
scope=coluser_pass/th
scope=colstaus/th";
scope=colinsert_time/th";
"/tr";
$SQL
=
"select
*
from
user_info";
$query
mysql_query($SQL);
//SQL查询语句
while
($row
mysql_fetch_array($query)){
//使用while循环mysql_fetch_array()并将数据返回数组
onmouseout=this.style.backgroundColor=''
bgcolor=#CCCCCC";
"td$row[0]/td";
//输出数组中数据
"td$row[1]/td";
"/table";输出记录截图
以上就是土嘎嘎小编为大家整理的php取出数据库记录相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!