2013-02-27 71 views
-2

任何人都可以告訴我什麼是在這個大壩代碼中的錯誤我瘋狂地搜索有關的錯誤,但沒有任何成功 錯誤是,我沒有從任何數據表爲什麼會發生這種情況? plz幫助我檢索數據並顯示在droplist(php/mysql)

的index.php

<html> 
<head> 
</head> 
<body> 
<form action="index.php" method="post"> 
<label for="searchByCountry">By Country</label> 
      <select name="searchByCountry" id="searchByCountry"> 
      <option id="0">--select your country--</option> 
      <?php 
       require_once('connfor_lamelchameltest.php'); 



       $getallCountries = mysql_query("SELECT country_name FROM country") or die("could not search for countries"); 
     if(mysql_num_rows($getallCountries) > 0) { 

       while($viewallCountries = mysql_fetch_array($getallCountries)){ 

       ?> 

       <option id="<?php echo $viewallCountries['country_name']; ?> "></option> 
       <?php } ?> 
       <?php } ?> 

      </select> 
</form> 
</body> 
</html> 
+0

你得到任何錯誤? – Winston 2013-02-27 13:31:09

+0

你已經試過了什麼?另外,你的數據庫中有什麼?你打電話過得怎麼樣? connfor_lamelchameltest.php裏面有什麼?在這個問題上工作。 – L0j1k 2013-02-27 13:31:37

+0

我試圖從包含country_id和country_name的表格國家調用或檢索數據,連接是由處理配置和連接的** connfor_lamelchameltest.php **進行的 – 2013-02-27 13:34:23

回答

0
<html> 
<head> 
</head> 
<body> 
<form action="index.php" method="post"> 
<label for="searchByCountry">By Country</label> 
      <select name="searchByCountry" id="searchByCountry"> 
      <option id="0">--select your country--</option> 
      <?php 
       require_once('connfor_lamelchameltest.php'); 



       $getallCountries = mysql_query("SELECT country_name FROM country") or die("could not search for countries"); 
     if(mysql_num_rows($getallCountries) > 0) { 

       while($viewallCountries = mysql_fetch_array($getallCountries)){ 

       ?> 

       <option value="<?php echo $viewallCountries['country_name']; ?> "> 
<?php echo $viewallCountries['country_name']; ?> 
</option> 
       <?php } ?> 
       <?php } ?> 

      </select> 
</form> 
</body> 
</html> 
+0

仍然沒有任何顯示爲什麼發生這種情況我不明白是什麼錯誤或在我的代碼中寫的錯誤 – 2013-02-27 13:52:33

+0

這可能是因爲mysql_num_rows返回0.我建議您不要使用mysql函數,因爲它們已被棄用,並且很快就會被移除。而是使用mysqli或者pdo。 – 2013-02-28 02:37:52

相關問題