尝试向mysql添加多个choose时出现问题

iyzzxitl  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(301)

我现在面临一个大问题。我的酒店公司从一家南非公司购买了一个用php制作的预订系统,他们的合同到期了,现在他们要花很多钱来更新合同和添加我们需要的新功能,所以现在所有的负担都留给我了…等等。所以我有这个表:

我想在每个房间增加一个多类型的房间。e、 g.:1号房间,类型:简单,两张床,三张床,table:

<div class="table-responsive">
        <table id="datatable-fixed-header" class="table datatable-show-all table-striped table-bordered">
            <thead>
                <tr>
                    <th>Nº</th>
                    <th>Floar</th>
                    <th>Room No.</th>
                    <th>Price per Night (&nbsp;In&nbsp;<?php echo $currency_symbol; ?>&nbsp;)</th>
                    <th>Price per Week (&nbsp;In&nbsp;<?php echo $currency_symbol; ?>&nbsp;)</th>
                    <th>Type</th>
                    <th>State</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (count($room_details) > 0) {
                    $s_no = 1;
                    foreach ($room_details as $room) {

                        echo'<tr>
                                    <td>' . $s_no . '</td>
                                    <td>' . $room["property_name"] . '</th>
                                    <td>' . $room["room_number"] . '</th>
                                    <td class="text-right format_currency_td">' . $room["room_standard_night_rate"] . '</td>
                                    <td class="text-right format_currency_td">' . $room["room_standard_weekly_rate"] . '</td>
                                    <td>' . $room["room_type_name"] . '</td>';

                        if ($room["room_status"] == "AVAILABLE")
                            echo'<td><span class="label label-success">' . $room["room_status"] . '</span></td>';
                        else if ($room["room_status"] == "OCUPADO")
                            echo'<td><span class="label label-info">' . $room["room_status"] . '</span></td>';
                        else if ($room["room_status"] == "MANUNTEINCE")
                            echo'<td><span class="label label-warning">' . $room["room_status"] . '</span></th>';
                        else if ($room["room_status"] == "OUT OF SERVICE")
                            echo'<td><span class="label label-danger">' . $room["room_status"] . '</span></td>';
                        echo'<td>';

                        if ($room["room_status"] != "OUT OF SERVICE")
                            echo'<div class="th_options_kit">
                                            <span class="th_options btn bg-teal-400 btn-icon btn-rounded btn_edit_room" data-room="' . $room["room_id"] . '" data-popup="tooltip" title="Edit Room" data-placement="left"><i class="icon-pen"></i></span>
                                            <span class="btn bg-danger-400 btn-icon btn-rounded btn_delete_room" data-room="' . $room["room_id"] . '" data-popup="tooltip" title="Delete Room" data-placement="left"><i class="icon-bin"></i></span>
                                        </div>';
                        else if ($room["room_status"] == "OUT OF SERVICE")
                            echo'<div class="th_options_kit">
                                            <span class="th_options btn bg-teal-400 btn-icon btn-rounded btn_edit_room" data-room="' . $room["room_id"] . '" data-popup="tooltip" title="Room is out of service" data-placement="left"><i class="icon-pen"></i></span>

                                        </div>';
                        echo'</td>
                                </tr>';

                        $s_no++;
                    }
                }else {

                }
                ?>
            </tbody>
        </table>
    </div>

php代码:

public function getRoom($where = FALSE) {

     $this->db->select('room.`room_id`, '
             . 'room.`property_id`, '
             . 'room.`room_number`, '
             . 'room.`room_type`,'
             . 'room.`room_standard_night_rate`,'
             . 'room.`room_standard_weekly_rate`,'
             . 'room.`room_status`,'
             . 'prop.`property_name`,'
             . 'room_type.`room_type_name`'
     );
     $this->db->from('hm_room room');
     $this->db->join('hm_room_type room_type', 'room.`room_type` IN (room_type.`room_type_id`)');
     $this->db->join('hm_property prop', 'room.`property_id` IN (prop.`property_id`)');

     if ($where !== FALSE) {
         foreach ($where as $whr) {
             $this->db->where_in($whr["column_name"], $whr["data"]);
         }
     }

     $this->db->order_by("prop.`property_name`", "ASC");
     $this->db->order_by("room.`room_number`", "ASC");

     $query = $this->db->get();
     return $query->result_array();
 }

请帮我解决这个问题。

u4dcyp6a

u4dcyp6a1#

我希望我能理解你的问题,你的table目前只是显示房间类型,例如简单。你现在想让它显示的是“简单,两张床”而不是“简单”?
然后,您需要做的是连接字段。我似乎看不出“两张床”的数据库字段是什么,但假设它是“房间\床”,那么您需要执行以下操作:
第一步是将数据库字段名添加到查询中,假设数据库中的字段名为“room\u beds”

$this->db->select('room.`room_id`, '
. 'room.`property_id`, '
. 'room.`room_number`, '
. 'room.`room_type`,'
. 'room.`room_standard_night_rate`,'
. 'room.`room_standard_weekly_rate`,'
. 'room.`room_status`,'
. 'prop.`property_name`,'
. 'prop.`room_beds`,' -- Add the here
. 'room_type.`room_type_name`');

最后,您需要将room\u beds字段连接到您已有的room\u type\u名称,如下所示:

<td>'. $room["room_type_name"] .' ,'. $room["room_beds"] .'</td>';

相关问题