HTML混编在PHP里来说,是多么简单的一件事情啊!
比如你在希望更换标题的index.php文件中,大可以这样写:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title><?php echo $title?></title>
</head>
<body>
这里是我的网站主内容~
</body>
</html>
看到里面有一段:<?php echo $title?>这样的标示了吧?只要你想办法把这个变量传进来,就直接搞定了不是吗?比如,你在这个网页的最上端写上查询数据库的代码,然后将本网页的标题赋值给$title,自然就可以做到了。
比如下面的例子:
<?php
$title='连接过程并取值'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title><?php echo $title?></title>
</head>
<body>
这里是我的网站主内容~
</body>
</html>
<?php/*如果下拉列表不为空执行以下*/
if($_POST['select']){
include ("conn.php")
$select=$_POST['select']
$search=$_POST['search']
$SQL = "SELECT * FROM emails where $select='$search' limit 0,10 "
$query=mysql_query($SQL,$conn)
while($row=mysql_fetch_array($query)){
echo'<tr>
<td width="120" height="31" align="center">'.$row[emaildata].'</td>
<td width="93" height="31" align="center">'.$row[name].'</td>
<td width="93" height="31" align="center">'.$row[type].'</td>
<td width="119" height="31" align="center">'.$row[emailtype].'</td>
<td width="119" height="31" align="center">'.$row[emailid].'</td>
<td width="173" height="31" align="center">'.$row[emailadd].'</td>
</tr>'
}}else{
/*如果下拉列表为空执行以下*/
$SQL = "SELECT * FROM emails limit 0,10"
$query=mysql_query($SQL,$conn)
while($row=mysql_fetch_array($query)){
echo'<tr>
<td width="120" height="31" align="center">'.$row[emaildata].'</td>
<td width="93" height="31" align="center">'.$row[name].'</td>
<td width="93" height="31" align="center">'.$row[type].'</td>
<td width="119" height="31" align="center">'.$row[emailtype].'</td>
<td width="119" height="31" align="center">'.$row[emailid].'</td>
<td width="173" height="31" align="center"> '.$row[emailadd].'</td>
</tr>'
}}
?>