2
<?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>

I am getting values from a table from a database and the values should be displayed inside a dropdown list. I have used the above code but it is not displaying anything. Can anyone help in this issue?

3
  • What is it displaying? This should at least display something because you are using echo. Commented Dec 14, 2015 at 8:44
  • First, you assign the query to $sql1 and never use it. I don't know the framework you are using, but you call $conn->query after that. The variable you pass in to that is $sqll, the first is a number at the end, the second is a lower case L. Aside from that, try echo "<option>{$data[room_type_name]}</option>"; Commented Dec 14, 2015 at 8:47
  • its displaying "Select one" only. Commented Dec 14, 2015 at 8:51

1 Answer 1

5

You have a typo

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

should be

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

it is a one, not an L

Sign up to request clarification or add additional context in comments.

1 Comment

You will have to supply more information. It still not working isn't much to work with. Did you test (with a print_r() command for example) whether $results holds any values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.