将表中的值从数据库显示到下拉列表中

时间:2015-12-14 08:40:38

标签: php wordpress

<?php
   include 'ASEngine/AS.php';

   if(!$login->isLoggedIn())
       header("Location: login.php");
   $user = new ASUser(ASSession::get("user_id"));
   $userInfo = $user->getInfo();

   //basic include files
   require_once("../db.php");

   $nav = 'hotels';

   $hotel_id = '1';

   //Messages
   include 'inc/messages.php';

   $sql1 = mysqli_query($conn,"SELECT room_type_name FROM hotel_room_type WHERE hotel_id = '$hotel_id'");

?>

HTML code:

<div class="form-row row-fluid">
    <div class="span12">
        <div class="row-fluid">
            <label class="form-label span3">Room Name</label>
            <?php echo "<select>";
                echo "<option value=''>Select One</option>"; 
                $results =  $conn->query($sqll);
                foreach ($results as $data) {
                   echo "<option>$data[room_type_name]</option>";  
                }
               echo "</select>";
           ?>

        </div>
    </div>
</div>

我从数据库中的表中获取值,并且值应显示在下拉列表中。我使用了上面的代码,但它没有显示任何内容。任何人都可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:5)

你有一个错字

 $results =  $conn->query($sqll);

应该是

 $results =  $conn->query($sql1);

它是一个,而不是L