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

慕田峪7331174
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
您的代碼中有一些語(yǔ)法錯(cuò)誤,其中之一是您將您設(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.
}
- 1 回答
- 0 關(guān)注
- 141 瀏覽
添加回答
舉報(bào)
0/150
提交
取消