资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PHP数据库数据HTML,php数据库函数

将PHP文件取出的数据库数据显示在前端HTML文件某个div中的几种方法

第一种,使用smarty模板引擎

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网站空间、营销软件、网站建设、若羌网站维护、网站推广。

php文件:

$smarty-assign('data','hello world');

$smarty-display('index.html');

index.html文件:

div{$data}/div

输出hello world

第二种,使用PHP变量直接输出

php文件:

$data = 'hello world';

require 'index.html';

index.html:文件:

div?php echo $data;?/div

php怎么从数据库里获取到值在html页面上输出?

用php判断查询数组是否为空,不为空就将给html赋值,控制是否显示图片。

$sql = "select * from ‘_goods_attr‘ where ‘attr_value‘=‘ ’";php查询,$res=mysql_query($sql);php处理,$arr = mysql_fetch_assoc($res);转为数组,后面就是自己判断数组是否为空和给html模板赋值的事情了。

$selv=array(1,2,3,4,5);//下拉列表值

$dbv=3;

foreach($selv as $s){

$issl='';

if($s==$dbv)  $issl='selected';

$str.="option value='$s' $issl-".$s."-/option";

}

echo 'select'.$str.'/select';

?

php从数据库里读出的HTML代码然后执行怎么实现

?php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

??php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

??php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

? 用以上先生成一个HTML文件,然后再用require_once("aaa.html");引进来就OK

php如何结合html调用数据?

在html中调用php内容,可以用script src="friendlinks.php"/script然后在friendlinks.php中调取数据库数据。并输出适当的html,或者输出xml、json都可以,只是图简单的话,只要输出html就行了。

PHP 如何将数据库中的数据输出到HTML的表格中

?php

$sql=mysql_query("select * from news");

while($row=mysql_fetch_assoc($sql)){

?

tr

td?php echo $row['title'];?/td

/tr

?php

}

?

输出到TD里面就行了


新闻标题:PHP数据库数据HTML,php数据库函数
分享地址:http://cdkjz.cn/article/dsshigd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220