一段逻辑判断,实现不了目的,求助
想只用一个页面,显示新闻系统的三种功能:"index.php?news_title=xxx?news_class=xxx",需要达到以下目的:
1,当news_title和news_class元素均为空或者都有值时,该页面显示全部新闻的标题列表;
2,当news_title和news_class两个元素中,一个有值另一个无值时,该页面显示元素有值的内容。
------算法逻辑和代码实现:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//首先,取得浏览器的传值: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)) {?> <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); }}
以上代码在最终显示时,全部显示为新闻的标题列表了,即:new_title列表。
敢问各位大虾,我这逻辑错了,还是写法有问题?
------解决方案--------------------
你这样写不太好呢。
你请求数据与逻辑与表现的html代码都搞在一起,
最好是先逻辑判断好。再去请求数据。最后一个foreach出html。
看你代码很吃力不如从新写了。=_=zzz
------解决方案--------------------
index.php?news_title=xxx?news_class=xxx
中的参数串,不是常规的格式
常规的是 index.php?news_title=xxx&news_class=xxx
你个到的是 array( 'news_title' => 'xxx?news_class=xxx')
需加工后方可使用
------解决方案--------------------
- PHP code
if ($a && $b) { // 显示全部} elseif ($a) { ;} elseif ($b) { ;}<br><font color="#e78608">------解决方案--------------------</font><br>url 要写作 index.php?news_title=xxx&news_class=xxx<br><br>$news_title = $news_class = '';<br>if(isset($_GET['news_title'])) $news_title = $_GET['news_title'];<br>if(isset($_GET['news_class'])) $news_class = $_GET['news_class'];<br><br>if($news_title != '' && $news_class != '') {<br> //两个都有<div class="clear"> </div>

負載均衡會影響會話管理,但可以通過會話複製、會話粘性和集中式會話存儲解決。 1.會話複製在服務器間複製會話數據。 2.會話粘性將用戶請求定向到同一服務器。 3.集中式會話存儲使用獨立服務器如Redis存儲會話數據,確保數據共享。

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

PHP會話的替代方案包括Cookies、Token-basedAuthentication、Database-basedSessions和Redis/Memcached。 1.Cookies通過在客戶端存儲數據來管理會話,簡單但安全性低。 2.Token-basedAuthentication使用令牌驗證用戶,安全性高但需額外邏輯。 3.Database-basedSessions將數據存儲在數據庫中,擴展性好但可能影響性能。 4.Redis/Memcached使用分佈式緩存提高性能和擴展性,但需額外配

Sessionhijacking是指攻擊者通過獲取用戶的sessionID來冒充用戶。防範方法包括:1)使用HTTPS加密通信;2)驗證sessionID的來源;3)使用安全的sessionID生成算法;4)定期更新sessionID。

本文比較了PHP和ASP.NET,重點是它們對大規模Web應用程序,性能差異和安全功能的適用性。兩者對於大型項目都是可行的,但是PHP是開源和無關的,而ASP.NET,


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具