【问题标题】:Problem trying to add multiple choose to mysql尝试将多个选择添加到 mysql 时出现问题
【发布时间】:2019-05-07 11:23:29
【问题描述】:

我在这里遇到了一个大问题。我的酒店公司从一家南非公司购买了一个使用 PHP 制作的预订系统,他们的合同到期了,他们现在收取大量费用来更新合同并添加我们需要的新功能,所以现在所有的负担都留给了我......等等。所以我有这张桌子:

我想在每个房间添加多种类型的房间。例如:房间 1,类型:简单,两张床,三张床 表代码:

<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();
 }

请帮我解决这个问题。

【问题讨论】:

  • 那么你的问题是什么?
  • 如何将多个选择保存到以 dB 为单位的 Room (room_type) 表中,并将其作为 Room_type (room_type_name) Simple, Suite 回显

标签: php mysql html-table


【解决方案1】:

我希望我能理解您的问题,您的桌子目前只显示房间类型,例如简单的。您希望它现在显示“简单,两张床”而不是“简单”吗?

然后你需要做的是连接你的字段。我似乎看不到“两张床”的数据库字段,但假设它是“room_beds”,那么您需要执行以下操作:

第一步是在查询中添加数据库字段名,假设数据库中的字段名叫做“room_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_beds 字段连接到你已经拥有的 room_type_name 如下:

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

【讨论】:

  • 很好,但是。有两个 DB 表: 1. Room : Room_I'd, room_number, room_type [应该记录为 1,2 而不是 1] 2. Room_type: room_type_id, room_type_name... 所以,当您预订房间时,它应该保存房间从房间表中输入 1,2 并读取房间类型名称并回显为 Simple, Suite。
  • 顺便说一句,对不起我的英语不好。
猜你喜欢
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多