亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

queryResults 和其后的多個 if 語句

queryResults 和其后的多個 if 語句

PHP
江戶川亂折騰 2022-06-17 16:18:01
在我的 php 代碼中,我顯示了數據庫的結果,一切都很好?,F在我添加了一行文本,顯示返回的行數。我不喜歡它顯示“有 1 個結果”和“有 5 個結果”等。我做了一個 if 語句“如果 $queryResult = 1”然后回顯“有 1 個結果”,還有 "if $queryResult > 1" echo "There are xx results",然后 "if $queryResult > 0" 回顯所有結果行?,F在,這是代碼,除了在只有 1 個結果時使用不正確的“are”和“results”外,它可以工作:$queryResult = mysqli_num_rows($result);echo "There are ".$queryResult." results.";if ($queryResult > 0) { // output data of each rowwhile($row = mysqli_fetch_assoc($result)) { // Display each field of the records.所以,我嘗試了這段代碼:$queryResult = mysqli_num_rows($result);//echo "There are ".$queryResult." results.";if ($queryResult = 1) {echo "There was ".$queryResult." lesson found.";}elseif ($queryResult > 1) {echo "There were ".$queryResult." lessons found.";}else ($queryResult > 0) { // output data of each rowwhile($row = mysqli_fetch_assoc($result)) { // Display each field of the records.它打破了頁面,出現以下錯誤:語法錯誤,意外的'while'(T_WHILE)我敢肯定還有更多錯誤,我敢肯定我錯過了關于第一個if和elseif語句的一些東西,但是什么是嗎?我究竟做錯了什么?我還在花括號中包含了第一個 if 和 elseif 語句,但這也不起作用。我知道使用“is”和“are”之間的區別是微不足道的,但這是在一個網站上為學習英語作為第二語言的人使用的,這意味著它應該正確使用英語。并且“有 1 個結果”對于新學習者來說并不是很好的英語。
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

您的代碼中有一些語法錯誤,其中之一是您將您設置$queryResult為1:


if ($queryResult = 1) 

你要:


if ($queryResult == 1) 

但是,像這樣壓縮代碼更容易:


$rsltCount = mysqli_num_rows($result);

echo  $rsltCount === 1 ? "There is 1 result." : "There are ".$rsltCount." results.";


while($row = mysqli_fetch_assoc($result)) 

    // Display each field of the records.

}


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號