第一種,使用smarty模板引擎

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國際域名空間、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、若羌網(wǎng)站維護(hù)、網(wǎng)站推廣。
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判斷查詢數(shù)組是否為空,不為空就將給html賦值,控制是否顯示圖片。
$sql = "select * from ‘_goods_attr‘ where ‘a(chǎn)ttr_value‘=‘ ’";php查詢,$res=mysql_query($sql);php處理,$arr = mysql_fetch_assoc($res);轉(zhuǎn)為數(shù)組,后面就是自己判斷數(shù)組是否為空和給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 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); //選擇數(shù)據(jù)庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標(biāo)題','新聞內(nèi)容'),array('新聞標(biāo)題2','新聞內(nèi)容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"));//讀取模板中內(nèi)容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內(nèi)容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內(nèi)容寫進(jìn)生成的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); //選擇數(shù)據(jù)庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標(biāo)題','新聞內(nèi)容'),array('新聞標(biāo)題2','新聞內(nèi)容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"));//讀取模板中內(nèi)容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內(nèi)容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內(nèi)容寫進(jìn)生成的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); //選擇數(shù)據(jù)庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標(biāo)題','新聞內(nèi)容'),array('新聞標(biāo)題2','新聞內(nèi)容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"));//讀取模板中內(nèi)容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內(nèi)容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內(nèi)容寫進(jìn)生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //刪除文件
? 用以上先生成一個HTML文件,然后再用require_once("aaa.html");引進(jìn)來就OK
在html中調(diào)用php內(nèi)容,可以用script src="friendlinks.php"/script然后在friendlinks.php中調(diào)取數(shù)據(jù)庫數(shù)據(jù)。并輸出適當(dāng)?shù)膆tml,或者輸出xml、json都可以,只是圖簡單的話,只要輸出html就行了。
?php
$sql=mysql_query("select * from news");
while($row=mysql_fetch_assoc($sql)){
?
tr
td?php echo $row['title'];?/td
/tr
?php
}
?
輸出到TD里面就行了
標(biāo)題名稱:PHP數(shù)據(jù)庫數(shù)據(jù)HTML,php數(shù)據(jù)庫函數(shù)
鏈接地址:http://chinadenli.net/article11/dsshigd.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、品牌網(wǎng)站建設(shè)、Google、網(wǎng)站導(dǎo)航、網(wǎng)站維護(hù)、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)