Jump to content

webdeveloper123

Members
  • Posts

    437
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by webdeveloper123

  1. are you sure your not missing a: . or: .. before the image path? so: <img src="../assets/img/central-business-district-singapore.jpg">
  2. Someone can correct me if I'm wrong, but can't you just create a range of array values like (a,z) instead of writing every alphabetic character
  3. Oh I get it. $reservedrooms = $_POST['reservedrooms'] ?? ''; Is storing a blank or NULL value If a room is not selected, it is then passing the NULL or blank value to the array function, thus the error message. Is that right?
  4. Hey dodgeitorelse3, I changed it to: $reservedrooms = $_POST['reservedrooms']; And: $reservedrooms = $_POST['reservedrooms'] ?? 0; On both of them, I still get the same error. And on the first one I get an additional error: Warning: Undefined array key "reservedrooms" in /var/www/vhosts/ booking.php on line 25 Thanks
  5. Hey Barand, No it doesn't look like anything is being over written. But I do have a count() statement later on on $reservedrooms so that I can output how many rooms the user has booked. But I can't see how the 2 are linked. Here is my full code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Booking</title> </head> <body> <?php include 'includes/db.php'; include 'includes/functions.php'; $reservedrooms = []; $today = new DateTime(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $reservedrooms = $_POST['reservedrooms'] ?? ''; $arrivalDate = $_POST['arrivaldate']; $departureDate = $_POST['departuredate']; $totaladults = $_POST['numofadults'] ?? ''; $totalchild = $_POST['numofchild'] ?? ''; $arrivalObj = new DateTime($arrivalDate); $departureObj = new DateTime($departureDate); $difference = $arrivalObj->diff($departureObj); $formattedInterval = $difference->format('%d'); $sqlbookquery = "SELECT r.room_id, rs.price FROM room AS r INNER JOIN roomsize AS rs ON r.size_id = rs.size_id;"; $statement1 = $pdo->query($sqlbookquery); $bookquery = $statement1->fetchAll(); if (!$reservedrooms) { } else { echo "You must select a room"; } $bookquery = array_filter($bookquery, fn($v)=>in_array($v['room_id'], $reservedrooms)); $totalprice = array_sum(array_column($bookquery, 'price')); $alltogether = $totalprice * $formattedInterval; $alltogether = number_format($alltogether); if ($formattedInterval == 0) { echo "Price for the night is: &pound;$totalprice<br>"; } else { echo "Total Price: &pound;$alltogether<br>"; } if ($arrivalObj == $departureObj) { echo "You will be charged for a minimum of 1 night<br>"; } else { echo $difference->format('%d nights<br>'); } if ($totaladults == 1) { echo "$totaladults Adult<br>"; } else { echo "$totaladults Adults<br>"; } if ($totalchild == 1) { echo "$totalchild Child<br>"; } elseif ($totalchild == 0) { echo ''; } else { echo "$totalchild Children<br>"; } $countrooms = count($reservedrooms); if ($countrooms == 1) { echo "$countrooms Room"; } else { echo "$countrooms Rooms"; } } ?> <p>Arrival date is:</p> <?= htmlspecialchars($arrivalObj->format('D, jS M Y')) ?> <p>Departure date is:</p> <?= htmlspecialchars($departureObj->format('D, jS M Y')) ?> </body> </html> Thanks
  6. Hey Barand, Sorry quick question. I am using the following code: $bookquery = array_filter($bookquery, fn($v)=>in_array($v['room_id'], $reservedrooms)); $totalprice = array_sum(array_column($bookquery, 'price')); Works great. But I was trying to find bugs in my app and I thought what If I tried to not select any rooms for booking from the search screen and just press "Book". It gives me this error: Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in /var/www/vhosts/:58 Stack trace: #0 /var/www/vhosts/): in_array() #1 [internal function]: {closure}() #2 /var/www/vhosts/: array_filter() #3 {main} thrown in /var/www/vhosts booking.php on line 58 Now I read the manual & I've used in_array before and the error is saying the second argument must be array (which in this case would be $reservedrooms) but it's receiving a string instead. So I'm assuming that the blank array is being interpreted as a string. I tried to fix is like this: if (!$reservedrooms) { echo "You must select a room"; } The echo line shows , but so does the original errror. Here is my related code: <?php $formattedInterval = $difference->format('%d'); if (!$reservedrooms) { echo "You must select a room"; } $bookquery = array_filter($bookquery, fn($v)=>in_array($v['room_id'], $reservedrooms)); $totalprice = array_sum(array_column($bookquery, 'price')); $alltogether = $totalprice * $formattedInterval; $alltogether = number_format($alltogether); ?> Thanks
  7. Hi Guys, Been looking at this for a few days now, but not sure how to go about it. I wanted to book 1 or more hotel rooms (depending on user input) but I'm stuck as to how to do it. I have the following code: (only showing relevant parts) <?php $reservedrooms = []; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $reservedrooms = $_POST['reservedrooms'] ?? ''; $sqlbookquery = "SELECT r.room_id, rs.price FROM room AS r INNER JOIN roomsize AS rs ON r.size_id = rs.size_id;"; $statement1 = $pdo->query($sqlbookquery); $bookquery = $statement1->fetchAll(); } ?> The reservedrooms array contains room_id from a checkbox on the search page. So If the user wanted to book 3 rooms, it will pick up the 3 matching ID's. I have tested this, it is working properly. Then to book the rooms I was thinking to compare the 2 arrays, and return the matching ID's, along with their price, then multiply that by the number of nights (I already done this part, I get the correct result of nights). It is stored in a variable. On the comparing arrays, I tried to use array_intersect but I got an error (probably because I was comparing 2 arrays that didn't match up) E.g the reservedrooms array has only room_id in there and the bookquery has room_id and price. That is just a theory. Is it even like that? There are several other array functions I was looking at but not sure which one to use. in_array, array_search, array_diff. Can someone please give me some help on how to go about this?
  8. It runs! Such a simple solution. Thanks Barand! And the area where the popup appears fixed itself!
  9. I know this is not a very good attempt, but this is where I've got to. Been at it since yesterday: <script> // When the user clicks on div, open the popup function myFunction(n) { var popup = document.getElementById("myPopup"); var roomid = 1; for (var i = 0; i < popup.length; i++) { popup.id += 'myPopup_' + n; n++; } //var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); } </script> And the HTML: <div class="popup" onclick="myFunction(1)">See all <span class="popuptext" id="myPopup"><?php echo "<p class='details'> Amenities: {$rooms['rmfac1']}</p>";?></span> </div> Thanks
  10. Hey Barand, Thanks for the code. So should n be an array? Or just a single value? And should I send in the room_id or should I do something like: n=1; Loop [condition] n++ append n to value in id attribute Because I already have the room_id in JSON. I did this: $roomid = []; foreach ($availableRooms as $row) { $roomid[] = $row["room_id"]; // Change this to the desired attribute } echo json_encode($roomid); Thanks
  11. Would this mean that say if I returned 4 rooms (Room id's - 4,6,12,22) than the id=mypopup is always going to have that roomid after it. So every time Room Id 4 is returned, the id for that popup would always be id=mypop4? And another thing - When I click the popup, it always displays in the same position, regardless of which room it's associated with. Now I know why this happens, because in the CSS I have used position: absolute; and then used the top, bottom, left & right properties to fix it into place. So it will always display there. But how do I make it appear in context of where it was clicked on the page? Because at the moment, if I click on the last result, I have to scroll back to the top to view it. If this is going to need more JS, I might as well do the lot whilst I'm at it.
  12. Shall I just changed it from Id=myPopUp to class=myPopUp and edit the JS?
  13. Actually, that makes sense. I got the popup from: https://www.w3schools.com/howto/howto_js_popup.asp
  14. Shall I do this? SET GLOBAL group_concat_max_len = 9999999; Although in the manual it says...... So I guess the question is - is 9999999 bigger than max_allowed_packet?
  15. hmm...I'm no expert but I can't see what's wrong with it. Because if I take that line outside of the popup it will display all amenities for all rooms - no problem. But as soon as I put it in the HTML for the popup (which is just a div and span element) it doesn't work
  16. Off the top of my head, I think the longest one (Penthouse suite) right at the bottom is 254 chars
  17. Ahh I think I know what you mean. I run that query and I get: 1048576 So after a google of it, the default length is 1024. So you are saying I am trying to return more than the default, that's why its cutting off at a certain point?
  18. Hey Requinix, Here it the ouputted HTML: <div class="searchresults"> <div class="perpicture"> <img class="picture" src="images/superiorqueen.png"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 825.00</p> <p class='details'> Amenities: Queen Size Bed &bull; Mini-Bar &bull; WiFi &bull; Wheel chair access &bull; Safe</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Wheel chair access<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorqueen.png"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 825.00</p> <p class='details'> Amenities: WiFi &bull; Wheel chair access &bull; Safe &bull; 55 Inch Smart TV &bull; Queen Size Bed</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Wheel chair access<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorqueenTwin.webp"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 850.00</p> <p class='details'> Amenities: Safe &bull; 55 Inch Smart TV &bull; Twin Beds &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorqueenTwin.webp"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 850.00</p> <p class='details'> Amenities: Safe &bull; 55 Inch Smart TV &bull; Twin Beds &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorqueen4.jpg"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 4</p> <p class="details"> Price 900.00</p> <p class='details'> Amenities: WiFi &bull; Twin Beds &bull; Safe &bull; 55 Inch Smart TV &bull; Queen Size Bed</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorqueen4.jpg"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 4</p> <p class="details"> Price 900.00</p> <p class='details'> Amenities: Safe &bull; 55 Inch Smart TV &bull; Queen Size Bed &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorking.png"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior King</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 930.00</p> <p class='details'> Amenities: King Size Bed &bull; Mini-Bar &bull; WiFi &bull; Safe &bull; 55 Inch Smart TV</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>King Size Bed<br>Mini-Bar<br>Safe<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorking.png"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior King</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 930.00</p> <p class='details'> Amenities: King Size Bed &bull; Mini-Bar &bull; WiFi &bull; Safe &bull; 55 Inch Smart TV</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>King Size Bed<br>Mini-Bar<br>Safe<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorking.png"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior King</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 930.00</p> <p class='details'> Amenities: Safe &bull; 55 Inch Smart TV &bull; King Size Bed &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>King Size Bed<br>Mini-Bar<br>Safe<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/superiorking2bed.jpg"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior King</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 980.00</p> <p class='details'> Amenities: Safe &bull; 55 Inch Smart TV &bull; Twin Beds &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/deluxeking2bed.webp"> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Deluxe King</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 1100.00</p> <p class='details'> Amenities: WiFi &bull; King Size Bed &bull; Air Conditioning &bull; 55 Inch Smart TV &bull; Bath Robes</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>King Size Bed<br>Mini-Bar<br>Safe<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/juniorsuite.png"> </div> <div class="resultdetails"> <h2> Suite</h2> <h1> Junior Suite</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 1300.00</p> <p class='details'> Amenities: Mini-Bar &bull; WiFi &bull; Views over Hyde Park &bull; King Size Bed &bull; Air Conditioning</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>King Size Bed<br>Mini-Bar<br>Safe<br>Views over Hyde Park<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/juniorsuite.png"> </div> <div class="resultdetails"> <h2> Suite</h2> <h1> Junior Suite</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 1300.00</p> <p class='details'> Amenities: 55 Inch Smart TV &bull; Bath Robes &bull; Safe &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>King Size Bed<br>Mini-Bar<br>Safe<br>Views over Hyde Park<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/executivesuite.png"> </div> <div class="resultdetails"> <h2> Suite</h2> <h1> Executive Suite</h1> <p class="details"> Sleeps 4</p> <p class="details"> Price 2400.00</p> <p class='details'> Amenities: Mini-Bar &bull; Views over Hyde Park &bull; WiFi &bull; Bath Robes &bull; Turndown Service</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>King Size Bed<br>Mini-Bar<br>Safe<br>Turndown Service<br>Twin Beds<br>Views over Hyde Park<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/executivesuite.png"> </div> <div class="resultdetails"> <h2> Suite</h2> <h1> Executive Suite</h1> <p class="details"> Sleeps 4</p> <p class="details"> Price 2400.00</p> <p class='details'> Amenities: Twin Beds &bull; Safe &bull; King Size Bed &bull; Mini-Bar &bull; WiFi</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>King Size Bed<br>Mini-Bar<br>Safe<br>Turndown Service<br>Twin Beds<br>Views over Hyde Park<br>WiFi</p></span> </div> </div> <div class="perpicture"> <img class="picture" src="images/penthousesuite.png"> </div> <div class="resultdetails"> <h2> Signature Suite</h2> <h1> The Penthouse Suite</h1> <p class="details"> Sleeps 10</p> <p class="details"> Price 7000.00</p> <p class='details'> Amenities: WiFi &bull; Turndown Service &bull; Twin Beds &bull; Personal working desk &bull; Nespresso coffee machine</p> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Air Conditioning<br>Bath Robes<br>Bottle of Champagne on arrival<br>King Size Bed<br>Mini-Bar<br>Nespresso coffee machine<br>Personal working desk<br>Queen Size Bed<br>Safe<br>Turndown Service<br>Twin Beds<br>Views over Hyde Park<br>WiFi</p></span> </div> </div> </div> And the screenshot: Thanks
  19. Hey Guys, Sorry if this thread is in the wrong place, I posted it here because I wasn't sure if the problem was with the PHP, JS or CSS (or maybe all!) I am making an online room reservation system. I'm returning search results. Now, in the results I am limiting to only show 5 room amenities (called facilities in the sql). This bit is fine. Rooms range from having 6 to 14 amenities, so because I didn't want to overload with information and wanted all the search result boxes to be the same size I thought I'd have the Amenities listed and then next to it I would have a "See All" text that when you click on it, it shows all amenities for that room in a JS popup. I've got the code for the popup. Now here is my SQL: $sql = "SELECT rs.description , rs.sleeps , rs.image , rs.price , substring_index(GROUP_CONCAT(f.description separator ' &bull; '), ' &bull; ', 5) as rmfac , rt.description as rmtype , r.room_id , r.room_number , GROUP_CONCAT(DISTINCT f.description SEPARATOR '<br>') AS rmfac1 FROM room as r JOIN roomtype as rt ON r.roomtype_id = rt.roomtype_id JOIN roomsize as rs ON r.size_id = rs.size_id JOIN room_facility as rf ON rf.size_id = rs.size_id JOIN facility as f ON rf.facility_id = f.facility_id LEFT JOIN room_booking as rb ON r.room_id = rb.room_id AND rb.departureDate > :arrival AND rb.arrivalDate <= :departure WHERE rb.room_id IS NULL GROUP BY room_id;"; rmfac displays the 5 amenities which is fine. rmfac1 is supposed to show all of them. If I do this: <?php echo "<p class='details'> Amenities: {$rooms['rmfac1']}</p>";?> It shows all amenities, no problem. But as soon as I try make it appear in the popup, it will only show maximum of 6, even though some have more than 6. Now even in the popup, If I view HTML source, I can see the amenities output for all rooms, all match up - but only show 6 in the popup First I thought it was my CSS, so I played around with it, made it massive in size thinking it's hidden somewhere, but to no avail. Here is my code: (relevant parts) <div class="searchresults"> <?php foreach ($availableRooms as $rooms) { ?> <div class="perpicture"> <img class="picture" src="images/<?= htmlspecialchars($rooms['image']) ?>"> </div> <div class="resultdetails"> <h2> <?= htmlspecialchars($rooms['rmtype']) ?></h2> <h1> <?= htmlspecialchars($rooms['description']) ?></h1> <p class="details"> Sleeps <?= htmlspecialchars($rooms['sleeps']) ?></p> <p class="details"> Price <?= htmlspecialchars($rooms['price']) ?></p> <?php echo "<p class='details'> Amenities: {$rooms['rmfac']}</p>";?> <div class="popup" onclick="myFunction()">See all <span class="popuptext" id="myPopup"><?php echo "<p class='details'> Amenities: {$rooms['rmfac1']}</p>";?></span> </div> </div> <?php } ?> </div> <script> // When the user clicks on div, open the popup function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); } </script> Here is the CSS for the popup: .popup { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* The actual popup */ .popup .popuptext { visibility: hidden; width: 360px; background-color: #BEBEBE; color: black; text-align: center; padding: 8px 0; position: absolute; z-index: 1; bottom: 50%; left: -60px; margin-left: -80px; height: 500px; top: 110%; } } /* Toggle this class - hide and show the popup */ .popup .show { visibility: visible; -webkit-animation: fadeIn 1s; animation: fadeIn 1s; } /* Add animation (fade in the popup) */ @-webkit-keyframes fadeIn { from {opacity: 0;} to {opacity: 1;} } @keyframes fadeIn { from {opacity: 0;} to {opacity:1 ;} } Can someone help please? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.