PHP与html混编中if else是否写错了
<?/*如果下拉列表不为空执行以下*/if($_POST['select']){include("conn.php");$select=$_POST['select'];...
<?
/*如果下拉列表不为空执行以下*/
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)){
?>
<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)){
?>
<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>
<?
}
?>
<? } ?>
跪求各位大爷帮我看一下。总感觉这里if else混编出了问题。麻烦给出正确的写法,谢谢各位了。 展开
/*如果下拉列表不为空执行以下*/
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)){
?>
<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)){
?>
<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>
<?
}
?>
<? } ?>
跪求各位大爷帮我看一下。总感觉这里if else混编出了问题。麻烦给出正确的写法,谢谢各位了。 展开
5个回答
展开全部
<?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>';
}}
?>
追问
这位老师,请问怎么能联系到您呢。。。。
追答
q 196859961
展开全部
include ("conn.php");写在if-else 语句之外。还有保证conn.php 文件不要有错,同时这个文件中要有下面代码中用到的$conn 这个变量。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?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>';
}}
?>
/*如果下拉列表不为空执行以下*/
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>';
}}
?>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的include ("conn.php");数据库只有在if($_POST['select'])才调用 把他放到外面这样就都会调用到
追问
我想对根据下拉列表传过来的参数进行分页,但是这时候出错了。。。请问怎么联系您呢。。。真的是跪求大神指点。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
逻辑上没错,但是<?php。最好用这个写法,有些环境下,你那不认识的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询