检索数据并在下拉列表中显示(php / mysql)

时间:2013-02-27 13:29:13

标签: php mysql dreamweaver

任何人都可以告诉我这个大坝代码中的错误是什么我疯狂地搜索错误但没有任何成功 错误是我没有从表中获取任何数据为什么会发生?请帮助我

的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>

1 个答案:

答案 0 :(得分: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>