十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
试编写代码如下:
金湖网站建设公司创新互联,金湖网站设计制作,有大型网站制作公司丰富经验。已为金湖近千家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的金湖做网站的公司定做!
?php
//从数据库根据 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
tr
td bgcolor="?php echo getColor($mysqli,'2')?"2/td
/tr
tr
td bgcolor="?php echo getColor($mysqli,'3')?"3/td
/tr
/table
?php
$mysqli-close();
?
代码如下:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"table
width=572
height=56
border=0
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
$conn=mysql_connect("localhost","root","");
$select=mysql_select_db("books",$conn);
$query="insert into computers(name,price,publish_data) ";
$query.="values('JSP',28.00,'2008-11-1')";
$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 "价格:".$row[2]."br";
echo "出版日期:".$row[3]."br";
echo "br";
}
//以下是使用mysql_fetch_array()函数来获取到查询结果
while($row=mysql_fetch_array($result))
{
echo "书号:".$row[0]."br";
echo "书名:".$row[1]."br";
echo "价格:".$row["price"]."br";
echo "出版日期:".$row["publish_data"]."br";
echo "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";
echo "br";
}
?