Advertisement
Guest User

Untitled

a guest
Feb 19th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. require_once("../resources/php/connection.php");
  3.  
  4. $park = $_POST["park"];
  5. $lecturestyle_id = $_POST["lecturestyle"];
  6. $group_size = $_POST["groupsize"];
  7. $roomstructure_id = $_POST["roomstructure"];
  8. $array = explode(",", $_POST["facilities"]);
  9.  
  10. // change Mon here
  11.  
  12. echo '<td class="gridSide">
  13. Mon
  14. ';
  15.  
  16. // build facilities search
  17.  
  18. for($i = 0; $i < count($array); $i++){
  19. if ($array[$i]!=0) {
  20. $fac .= ' AND facilities_id='.$array[$i].'';
  21. }
  22. else
  23. $fac .= '';
  24. }
  25.  
  26. echo '</td>';
  27.  
  28.  
  29. for ($i = 1; $i <= 9; $i++)
  30. {
  31.  
  32. // change mon here
  33.  
  34. echo '<td class="box" id="mon'.$i.'">';
  35.  
  36. // dynamically build sql query
  37.  
  38. $sql =
  39. "
  40. SELECT DISTINCT COUNT(*) FROM ts_room rm
  41. LEFT JOIN ts_roomfacilities rf
  42. ON rm.id = rf.room_id
  43. LEFT join ts_facilities f
  44. ON f.id = rf.facilities_id
  45. LEFT JOIN ts_building b
  46. ON rm.building_id=b.id
  47. WHERE capacity>=:group_size";
  48.  
  49. $searchArray[':group_size'] = $group_size;
  50. $sql .= $fac;
  51.  
  52. if($park!="Any") {
  53. $sql .= " AND b.park_id=:park";
  54. $searchArray[':park'] = $park;
  55. }
  56.  
  57. if($lecturestyle_id!="Any") {
  58. $sql .= " AND lecturestyle_id=:lecturestyle_id";
  59. $searchArray[':lecturestyle_id'] = $lecturestyle_id;
  60. }
  61.  
  62. if($roomstructure_id!="Any") {
  63. $sql .= " AND roomstructure_id=:roomstructure_id";
  64. $searchArray[':roomstructure_id'] = $roomstructure_id;
  65. }
  66.  
  67. $sql .= " AND rm.id NOT IN
  68. (SELECT COUNT(*)
  69. FROM ts_request rq
  70. LEFT JOIN ts_allocation a ON a.request_id = rq.id
  71. WHERE
  72. day_id=1 AND period_id=:period
  73. OR a.status IS NOT NULL
  74. AND a.status IN ('Pending','Declined','Failed'))";
  75.  
  76. $searchArray[':period'] = $i;
  77.  
  78. $stm = $pdo->prepare( $sql );
  79. $stm->execute(array( $searchArray));
  80. $rows = $stm->fetchColumn();
  81.  
  82. echo $rows.'<br>free</td>';
  83. echo '</td>';
  84.  
  85. }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement