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

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

如果實(shí)時搜索框輸入與數(shù)據(jù)庫不匹配,如何顯示未找到數(shù)據(jù)?

如果實(shí)時搜索框輸入與數(shù)據(jù)庫不匹配,如何顯示未找到數(shù)據(jù)?

PHP
開滿天機(jī) 2021-04-30 14:15:57
<?php$output = "";if(isset($_POST["query"])){ $search = $_POST["query"]; $sql = ("  SELECT * FROM `products`   WHERE productName LIKE :sText  OR productLine LIKE :sText  OR productVendor LIKE :sText  OR MSRP LIKE :sText "); $stmt=$db->prepare($sql);}elseif{ $sql = "SELECT * FROM products"; $stmt=$db->prepare($sql);}$stmt->execute(array(':sText'=>'%'. $search .'%'));foreach($stmt as $row){ $output = "           <div class='product_wrapper'>        <form method='post' action=''>        <table style='width:170px;height:143px;''>        <tr>        <td><input type='hidden' name='productCode' value=". $row['productCode']." />        <div class='name'>".$row['productName']."</div>        <div class='price'>RM". $row['MSRP']."</div></td>        </tr>        <table style='width:170px;height:60px'>        <tr>        <td><button type='submit' class='buy' style='margin: : 25px;'>Buy Now</button></td>        </tr>        </table>        </table>        </form>          </div> "; echo $output;}else{ echo 'Data Not Found';}?>為了添加其他未找到的回顯數(shù)據(jù),我對elseif條件所需的條件有疑問。我必須找出可以添加的elseif條件。感謝您的幫助。
查看完整描述

2 回答

?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個贊

您不能將else與foreach一起使用,因此需要在使用foreach語句之前檢查是否有任何結(jié)果。


if($stmt->rowCount() > 0) {

    foreach($stmt as $row)

    {

        $output = echo" 

          <div class='product_wrapper'>

        <form method='post' action=''>

        <table style='width:170px;height:143px;''>

        <tr>

        <td><input type='hidden' name='productCode' value=". $row['productCode']." />

        <div class='name'>".$row['productName']."</div>

        <div class='price'>RM". $row['MSRP']."</div></td>

        </tr>

        <table style='width:170px;height:60px'>

        <tr>

        <td><button type='submit' class='buy' style='margin: : 25px;'>Buy Now</button></td>

        </tr>

        </table>

        </table>

        </form>

        </div>";


     $output;

    }

} else {

    echo 'Data Not Found';

}


查看完整回答
反對 回復(fù) 2021-05-14
?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個贊

您可以rowCount用來獲取受影響的行數(shù)


試試這個


 if($stmt->rowCount() > 0) {

   //Loop throught the rows

 }else{

    echo "No matching records found.";

 }

檢查更多信息PDOStatement :: rowCount


查看完整回答
反對 回復(fù) 2021-05-14
  • 2 回答
  • 0 關(guān)注
  • 157 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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