donglian3055 2015-05-23 20:50
浏览 27

每间客房预订限6人

I am trying to build hostel booking system. The problem is, I'm getting stuck when it comes to limit of residents for each room.

What I am trying to do is, when the room is limited for 6 residents only, so the 7th person who trying to book will get error message "This room is full. Please book another room."

In this SQL, I want it to read the value of count, and if it is >=6, the error message will appear. unfortunately, it wont works

 <?php 
$result = mysql_query("SELECT COUNT(student_id) AS total FROM booking");
$row = mysql_fetch_row($result);
if (total < 7) { 
    echo 'We have reached our registration limit';
}
?>

Each room have different capacity of residents, so do I have to apply the SQL for each button?

Here is what I have. Once student click on the button, it will automatically save to database.

<table align="center" width="1100">
  <tr valign="baseline">
    <td><table cellspacing="0" cellpadding="2" border="1" bordercolor="white" bgcolor="#FFFF99"  width="1100" align="center">
      <tr>
        <th colspan="6" align="center" bgcolor="#CCFFFF"><h3>Block A Room </h3></th>
      </tr>
       <tr>
        <td align="center" width="50"><p>First Floor</p></td>
    <td align="center" width="220">
      <p>
    <form method="POST" name="form1" action="/turc/student_hostel.php"> 

    <button name="select_room" type="submit" value="6">A102 </button>

    <button name="select_room" type="submit" value="25">A105</button>
      </p>
      <p>
       <button name="select_room" type="submit" value="21">A101 </button>
        <button name="select_room" type="submit" value="23">A103 </button>
        <button name="select_room" type="submit" value="26">A106 </button>
        <button name="select_room" type="submit" value="24">A104 </button>
      </p>
    </form>

      </p> </td>
      <td align="center" width="224">
      <p>
      <form method="POST" name="form2" action="/turc/student_hostel.php"> 
        <button name="select_room" type="submit" value="28">A108 </button>
        <button name="select_room" type="submit" value="31">A111 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="27">A107 </button>
        <button name="select_room" type="submit" value="29">A109 </button>
        <button name="select_room" type="submit" value="32">A112 </button>
        <button name="select_room" type="submit" value="30">A110 </button>
      </p>
    </form>

      </p> </td>
      <td align="center" width="222">
      <p>
      <form method="POST" name="form3" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="34">A114 </button>
        <button name="select_room" type="submit" value="37">A117 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="33">A113 </button>
        <button name="select_room" type="submit" value="35">A115 </button>
        <button name="select_room" type="submit" value="38">A118 </button>
        <button name="select_room" type="submit" value="36">A116 </button>
      </p>
    </form>

      </p> </td>
      <td align="center" width="222">
      <p>
      <form method="POST" name="form4" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="40">A120 </button>
        <button name="select_room" type="submit" value="43">A123 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="39">A119 </button>
        <button name="select_room" type="submit" value="41">A121 </button>
        <button name="select_room" type="submit" value="44">A124 </button>
        <button name="select_room" type="submit" value="42">A122 </button>
      </p>
    </form>

      </p> </td>

    <td align="center" width="224">
      <p>
      <form method="POST" name="form5" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="46">A126 </button>
        <button name="select_room" type="submit" value="49">A129 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="45">A125 </button>
        <button name="select_room" type="submit" value="47">A127 </button>
        <button name="select_room" type="submit" value="50">A130 </button>
        <button name="select_room" type="submit" value="48">A128 </button>
      </p>
    </form>

      </p> </td>

      </tr>
  <tr>
    <td align="center" width="50"><p>Ground Floor</p></td>
    <td align="center" width="220"><p>    
      <form method="POST" name="form6" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="2">A002 </button>
        &nbsp;
        <button name="select_room" type="submit" value="4">A004</button>
          </p>
      <p>
        <button name="select_room" type="submit" value="1">A001 </button>
        &nbsp;
        <button name="select_room" type="submit" value="3">A003 </button>
      </p>
  </form>
      </td>

      <td align="center" width="224"><p>      
        <form method="POST" name="form7" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="6">A006 </button>
        &nbsp;
        <button name="select_room" type="submit" value="8">A008 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="5">A005 </button>
        &nbsp;
       <button name="select_room" type="submit" value="7">A007 </button>
      </p>
  </form>
      </td>

      <td align="center" width="222"><p>
      <form method="POST" name="form8" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="10">A010 </button>
        &nbsp;
        <button name="select_room" type="submit" value="12">A012 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="9">A009 </button>
        &nbsp;
       <button name="select_room" type="submit" value="11">A011 </button>
      </p>
  </form>
      </td>
      <td align="center" width="222"><p>
      <form method="POST" name="form9" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="14">A014 </button>
        &nbsp;
        <button name="select_room" type="submit" value="16">A016 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="13">A013 </button>
        &nbsp;
       <button name="select_room" type="submit" value="15">A015 </button>
      </p>
  </form>
      </td>
      <td align="center" width="224"><p>
      <form method="POST" name="form10" action="/turc/student_hostel.php">
        <button name="select_room" type="submit" value="18" >A018 </button>
        &nbsp;
        <button name="select_room" type="submit" value="20" >A020 </button>
      </p>
      <p>
        <button name="select_room" type="submit" value="17" >A017 </button>
        &nbsp;
       <button name="select_room" type="submit" value="19">A019 </button>
      </p>
      </form>
      </td>
    </table>
  </tr>

  <tr valign="baseline">

    <th>
   <input type=button onClick="location.href='/turc/select_block.php'" value='Return' class="myButton">
   </th>
  </tr>
  </table>

Please help me to finish my final project. I am really appreciate it.

  • 写回答

1条回答 默认 最新

  • doupi1532 2015-05-23 21:55
    关注
     <?php 
    $result = mysql_query("SELECT COUNT(student_id) AS total FROM booking");
    $row = mysql_fetch_object($result);
    $total =$row->total;
    if ($total > 6) { 
        echo 'We have reached our registration limit';
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数