第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

queryResults 和其后的多個 if 語句

queryResults 和其后的多個 if 語句

PHP
江戶川亂折騰 2022-06-17 16:18:01
在我的 php 代碼中,我顯示了數(shù)據(jù)庫的結(jié)果,一切都很好?,F(xiàn)在我添加了一行文本,顯示返回的行數(shù)。我不喜歡它顯示“有 1 個結(jié)果”和“有 5 個結(jié)果”等。我做了一個 if 語句“如果 $queryResult = 1”然后回顯“有 1 個結(jié)果”,還有 "if $queryResult > 1" echo "There are xx results",然后 "if $queryResult > 0" 回顯所有結(jié)果行?,F(xiàn)在,這是代碼,除了在只有 1 個結(jié)果時使用不正確的“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.它打破了頁面,出現(xiàn)以下錯誤:語法錯誤,意外的'while'(T_WHILE)我敢肯定還有更多錯誤,我敢肯定我錯過了關(guān)于第一個if和elseif語句的一些東西,但是什么是嗎?我究竟做錯了什么?我還在花括號中包含了第一個 if 和 elseif 語句,但這也不起作用。我知道使用“is”和“are”之間的區(qū)別是微不足道的,但這是在一個網(wǎng)站上為學(xué)習(xí)英語作為第二語言的人使用的,這意味著它應(yīng)該正確使用英語。并且“有 1 個結(jié)果”對于新學(xué)習(xí)者來說并不是很好的英語。
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗 獲得超13個贊

您的代碼中有一些語法錯誤,其中之一是您將您設(shè)置$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.

}


查看完整回答
反對 回復(fù) 2022-06-17
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號