0

それで、インターネット検索では解決できない問題に遭遇しました。誰かが送信をクリックして空になったときに「結果が見つかりません」とエコーする方法を見つけようとしています。過去に似たようなことをしたことがありますが、どうやってやったか思い出せません。ここに私がこれまでに持っているものがありますが、うまくいきません:

<?php
if ( empty($row_Recordset1) && isset($_POST['Submit']) ){
    echo "No results found";
}

何か案は?

4

1 に答える 1

0

多くのコードを書くのを忘れているようです...まず、最初に $_POST['Submit'] をチェックすることをお勧めします。 URL(ブラウザのアドレスバーに直接書き込むか、前のページからのリンクをたどる)またはフォームボタンをクリックして:

<?php
if (isset($_POST['Submit'])){
   // someone submitted the form
   // so, here you must check if results are available according to the submitted data

   //here all the necessary code to open a database connection, perform a mysql query  and save the results in $row_Recordset1

   //then you can check if the query returned no results
   if (empty($row_Recordset1) {
      echo "No results found"; 
   }
   else {
      // the code to print results here
   }

}
else {
   // no one submitted the form
   // so, here you should put the code to draw your html form
} 
?>
于 2013-10-27T11:58:31.777 に答える