<?php
include "config.ini.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/html; charset=gb2312" />
<title>例子</title>
<style type="text/css">
<!--
.STYLE1 { font-size: 12px;
color: #333333;
}
-->
</style>
</head><body>
<?php
if (!$_SESSION['user']) {
?>
<h3>对不起请登陆</h3>
<?php }
else{
?>
<table width="385" height="249" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" background="images/img.jpg">
<form id="form1" name="form1" method="post" action="">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">用户名:
<select name="charguid" size="1">
<?php }
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
$info_cx=mysql_fetch_array($query);
do{
?>
<option value="<?php} echo $info_cx[charguid];{?>"><?php} echo $info_cx[charname];{?></option>
<?php } while($info_cx=mysql_fetch_array($query)); {?>
</select></td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">城 市:
<select name="select2" size="1">
<option value="1">安徽</option>
</select>
</td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1"><p>地区:
<select name="select3" size="1">
<option value="8D02">上海</option> </select>
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php }?>
</body>
</html>
include "config.ini.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/html; charset=gb2312" />
<title>例子</title>
<style type="text/css">
<!--
.STYLE1 { font-size: 12px;
color: #333333;
}
-->
</style>
</head><body>
<?php
if (!$_SESSION['user']) {
?>
<h3>对不起请登陆</h3>
<?php }
else{
?>
<table width="385" height="249" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" background="images/img.jpg">
<form id="form1" name="form1" method="post" action="">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">用户名:
<select name="charguid" size="1">
<?php }
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
$info_cx=mysql_fetch_array($query);
do{
?>
<option value="<?php} echo $info_cx[charguid];{?>"><?php} echo $info_cx[charname];{?></option>
<?php } while($info_cx=mysql_fetch_array($query)); {?>
</select></td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">城 市:
<select name="select2" size="1">
<option value="1">安徽</option>
</select>
</td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1"><p>地区:
<select name="select3" size="1">
<option value="8D02">上海</option> </select>
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php }?>
</body>
</html>
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
$info_cx=mysql_fetch_array($query);
do{ 将:$info_cx=mysql_fetch_array($query); 去掉
你用的是do{}while();
我重新发下
<?php
include "config.ini.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/html; charset=gb2312" />
<title>例子 </title>
<style type="text/css">
<!--
.STYLE1 { font-size: 12px;
color: #333333;
}
-->
</style>
</head> <body>
<?php
if (!$_SESSION['user']) { //这里是判断SESSION里有没有登陆过的名字
?>
<h3>对不起请登陆 </h3>
<?php }
else{
?>
<table width="385" height="249" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" background="images/img.jpg">
<form id="form1" name="form1" method="post" action="">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">用户名:
<select name="charguid" size="1">
<?php }
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
$info_cx=mysql_fetch_array($query); //执行查找
do{
?>
<option value=" <?php} echo $info_cx[charguid];{?>"> <?php} echo $info_cx[charname];{?> </option> //将查找的内容加载到 菜单里
<?php } while($info_cx=mysql_fetch_array($query)); {?>
</select> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">城 市:
<select name="select2" size="1">
<option value="1">安徽 </option>
</select>
</td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1"> <p>地区:
<select name="select3" size="1">
<option value="8D02">上海 </option> </select>
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php }?>
</body>
</html>
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
while($info_cx=mysql_fetch_array($query){
}
比你那个不精简些?
php嵌入html文件
最好逻辑和页面分开
比如说一个页面,下面是html,上面一段是php 处理好数据,下面html引用数据.或者把html用include包含进来,这个只是简单的代码分离思想.
逻辑用if endif,whlie end while 支持的php什么的.
后来我在 里面加了个 else 就不对了 主要是 { } 嵌入好像某个部分错误了
下面是我的引入代码 config.ini.php
<?php
$hostnamemm="192.168.1.103";
$dbusermm="root";
$dbpasswordmm="5877777";
$dbnamemm="us_pa";
$dbmm=mysql_connect($hostnamemm,$dbusermm,$dbpasswordmm) or die(' <script language="javascript"> alert("数据库连接失败!");javascript:history.go(-1); </script>');
mysql_select_db($dbnamemm,$dbmm);
mysql_query("SET NAMES 'latin1'",$dbmm);
?>
<?php
include "config.ini.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/html; charset=gb2312" />
<title>例子 </title>
<style type="text/css">
<!--
.STYLE1 { font-size: 12px;
color: #333333;
}
-->
</style>
</head> <body>
<?php
if (!$_SESSION['user']) {
?>
<h3>对不起请登陆 </h3>
<?php }
else{
?>
<table width="385" height="249" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" background="images/img.jpg">
<form id="form1" name="form1" method="post" action="">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">用户名:
<select name="charguid" size="1">
<?php
$query=mysql_query("select charname,charguid from t_char where accname='dianmo' group by charname");
$info_cx=mysql_fetch_array($query);
do{
?>
<option value=" <?php echo $info_cx[charguid];?>"> <?php echo $info_cx[charname];?> </option>
<?php } while($info_cx=mysql_fetch_array($query)); ?>
</select> </td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1">城 市:
<select name="select2" size="1">
<option value="1">安徽 </option>
</select>
</td>
</tr>
<tr>
<td height="30" align="center" class="STYLE1"> <p>地区:
<select name="select3" size="1">
<option value="8D02">上海 </option> </select>
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p> </td>
</tr>
</table>
</form>
</td>
</tr>
<?php }?>
</table>
</body>
</html>你的好多<?php} 是这个是什么意思啊,太乱了.
</table>
---------------------------
</table>
<?php }?>
你标题上的“if() {}else{do{while()}}"就有问题!if () {
} else {
do{
} while ();
}你看看你的do...while之间多了多少花括号?你该不会是觉得PHP区的语法就是<?php}...{?>吧?
<?php
if (!$_SESSION['user']) {
?>
<h3>对不起请登陆 </h3>
<?php }
else{
?> 换成<?php
if (!$_SESSION['user']) {
echo '<h3>对不起请登陆 </h3>';
else{
?>
不是很好吗?当然这里有个人习惯问题。但是下面这里还是一小块一小块输出就很不爽了:do{
?>
<option value=" <?php} echo $info_cx[charguid];{?>"> <?php} echo $info_cx[charname];{?> </option> //将查找的内容加载到 菜单里
<?php } while($info_cx=mysql_fetch_array($query));
你可以这样:do{
echo '<option value="'.$info_cx['charguid'].'">'.$info_cx['charname'].'</option>'; //将查找的内容加载到 菜单里
} while($info_cx=mysql_fetch_array($query));