日期:2014-05-17 浏览次数:20389 次
//首先,取得浏览器的传值:news_title和news_class if(isset($_GET['news_class'])) { $news_class=$_GET['news_class']; } else { $news_class=''; } if(isset($_GET['news_title'])) { $news_title=$_GET['news_title']; } else { $news_title=''; } //然后开始判断,准备显示有关的内容 if ($news_title='')//当news_title元素为空时,开始判断news_class元素是否为空 { if ($news_class='')//news_class也为空,则该页面显示所有news表的news_title列表 { $sql="SELECT news_title,in_time FROM news"; $result = mysql_query($sql); while ($row=mysql_fetch_assoc($result)) { ?> <tr> <td> <?php echo $row['news_title']; ?> <?php echo $row['in_time']; ?> </td> </tr> <?php } mysql_free_result($result); } else//当news_class不为空,则该页面显示news_class的相关内容 { $sql="SELECT * FROM news where news_class='$news_class'"; $result = mysql_query($sql); while ($row=mysql_fetch_assoc($result)) { ?> <tr> <td><?php echo $row['news_title']; ?> <?php echo $row['in_time']; ?> </td> </tr> <?php } mysql_free_result($result); } } else //当news_title不为空值时,开始判断news_class是否为空 { if ($news_class='')//news_class为空,则该页面show出news_title的相关数据 { $sql="SELECT * FROM news where news_title='$news_title'"; $result = mysql_query($sql); while ($row=mysql_fetch_assoc($result)) { ?> <tr> <td> <?php echo $row['news_title']; ?> Author : <?php echo $row['news_author']; ?> Date : <?php echo $row['in_time']; ?> <?php echo $row['news_content']; ?> </td> </tr> <?php } mysql_free_result($result); } else//当news_class也不为空值时,则该页面显示所有news表的数据(和两者都为空时一样) { $sql="SELECT news_title,in_time FROM news"; $result = mysql_query($sql); while ($row=mysql_fetch_assoc($result)) { ?> <tr> <td><?php echo $row['news_title']; ?> <?php echo $row['in_time']; ?> </td> </tr> <?php } mysql_free_result($result); } }
if ($a && $b) { // 显示全部 } elseif ($a) { ; } elseif ($b) { ; }
------解决方案--------------------
url 要写作 index.php?news_title=xxx&news_class=xxx
$news_title = $news_class = '';
if(isset($_GET['news_title'])) $news_title = $_GET['news_title'];
if(isset($_GET['news_class'])) $news_class = $_GET['news_class'];
if($news_title != '' && $news_class != '') {
//两个都有