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

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

第一种,使用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>

1、首先, sudo su postgres命令进入postgres,如下图所示,然后进入下一步。

   

2、其次, 完成上述步骤后, \ c

 test \ dt \ d检查一些表格,如下图所示,然后进入下一步。

   

3、接着,完成上述步骤后,准备sql文件,如下图所示,然后进入下一步。

   

4、然后, 完成上述步骤后,SELECT *

 FROM person检查表的内容,如下图所示,然后进入下一步。

   

5、随后,完成上述步骤后, \ i

 /home/coffee/Downloads/person.sql导入文件,如下图所示,然后进入下一步。

   

6、最后, 完成上述步骤后,DROP

 TABLE person, *** 作完成,数据库里的内容就可以在html网页里面显示了,如下图所示。这样,问题就解决了。  

<?php require_once("mysql_class.php")

require_once("sys_conf.inc")

header('Content-Type:text/htmlCharset=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/htmlCharset=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/htmlCharset=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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7343416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存