一段逻辑判断,实现不了目的,求助
想只用一个页面,显示新闻系统的三种功能:index.php?news_title=xxx?news_class=xxx,需要达到以下目的:
1,当news_title和news_class元素均为空或者都有值时,该页面显示全部新闻的标题列表;
2,当news_title和news_class两个元素中,一个有值另一个无值时,该页面显示元素有值的内容。
------算法逻辑和代码实现:
php code//首先,取得浏览器的传值:news_title和news_classif(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)) {?>
author : date :
'xxx?news_class=xxx')
需加工后方可使用
------解决方案--------------------
php codeif ($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 != '') {
//两个都有