资讯

精准传达 • 有效沟通

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

php数据库html文本 php将数据库内容显示到网页

php如何结合html调用数据?

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

创新互联从2013年开始,是专业互联网技术服务公司,拥有项目网站制作、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元荥经做网站,已为上家服务,为荥经各地企业和个人服务,联系电话:18982081108

PHP从数据库读取数据批量生成HTML

首先创建html文件。可以以id字段作为文件名,你如果嫌短的话,再加上time()。

如 $filename=$row[id].time."html";

然后以可写的形式打开刚刚建立的文件,把读出的数据内容存放进去。一个文件就建成了。如果建成批量的,在读取数据表的时候,把代码加到while循环里就好了。

怎么用php把html表单内容写入数据库

1:首先要使用PHP的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)

2:然后使用INSERT INTO 语句用于向数据库表中插入新记录。

具体示例:

(1)首先创建了一个名为 "Persons" 的表,有三个列:"Firstname", "Lastname" 以及 "Age"。

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)

VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)

VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);

?

(2)其次创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。

html

body

form action="insert.php" method="post"

Firstname: input type="text" name="firstname" /

Lastname: input type="text" name="lastname" /

Age: input type="text" name="age" /

input type="submit" /

/form

/body

/html

(3)接着当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过

$_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?

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文本 php将数据库内容显示到网页
文章来源:http://cdkjz.cn/article/dopgcoe.html
多年建站经验

多一份参考,总有益处

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

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

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