Click here to Skip to main content
15,746,077 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In the table, the thing that will display in the room type column is the room rate. I want the room type to display in the room type column and room rate in the room rate column.

What I have tried:

This is my code.

<p><label> Room: </label>
      <select class="input-sm" name="rtype" id="rtype" required>
          $roomtype = "SELECT DISTINCT * FROM roomtypes";
          $roomresult = mysqli_query($conn, $roomtype);
          while ($row = mysqli_fetch_array($roomresult)) {?>
            <option value="<?php echo $row[2]; ?>"><?php echo $row[1];?> </option>
         <?php }
Updated 16-Oct-19 10:16am

1 solution

A general rule in SQL is to only call what you need to; and try to avoid using the * selector as it will grab all columns in whatever order they are in the table.
Where this comes into play when you want to display it; as you are calling the columns by their index number.
$roomtype = "SELECT DISTINCT RoomType, RoomRate FROM roomtypes";
This will get you only what you are using, and then you would know exactly what column names (RoomType, RoomRate) are at what indexes (0, 1)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900