RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php数据库取值 PHP读取数据库

php如何取数据库中内容

试编写代码如下:

我们提供的服务有:成都网站设计、做网站、微信公众号开发、网站优化、网站认证、贞丰ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的贞丰网站制作公司

?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();

?

php怎么从数据库取值

$urls = "192.168.0.128";//你的主机地址(一般是localhost)

$user = "root";//数据库用户名

$password = "111111";//数据库密码

$con = mysqli_connect($urls,$user,$password);//mysql数据库连接

mysqli_select_db($con,"le_test");//第二个参数为数据库名称

mysqli_query($con,"select click_num from fstk_zhi_click where id0");//查询所有click_num

mysqli_close($con);//关闭连接

php中获取数据库中字段值。

取到值后,在输出的时候%=变量*100%/100,这样用PHP把数据输入,后面跟/100的字符就可以了。


本文名称:php数据库取值 PHP读取数据库
URL分享:http://scyingshan.cn/article/hicghp.html