ardyandkari Posted July 28, 2008 Share Posted July 28, 2008 hello again. i am making a reservation system for a friend of my dad's. he needs simple, and what i am giving him will be simple on his end but confusculates the heck out of me. here is the issue: i am making a section where the user can view any reserved dates. this will be available from both the main site and the reservation area, just to make it easier for the owner of the resort. what i have for code came from the sams teach yourself php, mysql, and apache. this is the calendar code: <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\"> s <trong>$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { echo "<td>".$dayArray["mday"]." </td>\n"; $start += ADAY; } } echo "</tr></table>"; ?> the calendar works just fine. now i want to have it look at the db and anywhere there is a reservation for the selected cabin/camp site (will add that feature to the calendar later) it puts an x or a pop up link to show which of the selected sites are used. as of right now, they are not taking any payments over the internet. the calendar is just a helpful tool for their customers and also for them, so that they dont get double booked. what i was thinking was having this structure for the db: `cabin1` tinyint(1) NOT NULL, `cabin2` tinyint(1) NOT NULL, `cabin3` tinyint(1) NOT NULL, `cabin4` tinyint(1) NOT NULL, `cabin5` tinyint(1) NOT NULL, `cabin6` tinyint(1) NOT NULL, `cabin7` tinyint(1) NOT NULL, `camp1` tinyint(1) NOT NULL, `camp2` tinyint(1) NOT NULL, `camp3` tinyint(1) NOT NULL, `datefrom` date NOT NULL, `dateto` date NOT NULL, `month` varchar(20) NOT NULL (i have never really done this before, so if anyone has a better idea for db structure here, tell me. any help is much appreciated.) the cabin/camp areas are bool, so they either are or aren't reserved. the datefrom and dateto are the check in and out dates. the month would be for the use of the calendar. what i want to know is this: how do i split the datefrom/to portions to get the month? how would i have the indicators go on the calendar. thanks a lot. ardy Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/ Share on other sites More sharing options...
.josh Posted July 28, 2008 Share Posted July 28, 2008 as for getting the month from your date: // example date $x = "2000-02-06"; // if you want the month numerically like "02" $now = date("m",strtotime($x)); // if you want the month alpha like "Febuary" $now = date("F",strtotime($x)); as for how to have indicators go on the calendar, what do you mean by "go on?" Are you wanting all your cabins to be displayed on each day of the month, with(out) an X next to them? Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-601275 Share on other sites More sharing options...
ardyandkari Posted July 28, 2008 Author Share Posted July 28, 2008 what i was going to do was add a select box (or check boxes, i am not sure) where the user could select which cabin they wanted to view or "ALL" and it would display their selection on the calendar. if they just want to see "El Grande Cabin" they would select just that and the month they want to view and click submit and they would see the calendar with x's in the days that the cabin was already reserved or even the word reserved or something. Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-601559 Share on other sites More sharing options...
JonnoTheDev Posted July 28, 2008 Share Posted July 28, 2008 I would not use php's date functions to extract parts of the date from your db. Leave this out of the programming logic and let your SQL return this data like so: SELECT MONTH(dateField) AS month, DAYOFWEEK(dateField) etc..... What your require is query that will select a range of dates based on what year/month is showing on your calender. So lets say that the user is viewing August 2008 your SQL is going to return all dates in the selected month/year that have an entry in your reservations table so: FROM reservations WHERE MONTH(dateField) = 'selectedMonth' AND YEAR(dateField) = 'selectedYear' You would then build the results from the query into an array. When you are displaying the calender you will have a peice of code within the calender loop to check if the calender date is present in the array from the database query. If it is then the date is reserved and you can show this in the calender. Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-601570 Share on other sites More sharing options...
ardyandkari Posted August 2, 2008 Author Share Posted August 2, 2008 ok...new issue... here is the problem code. //checks string length---if 2 characters long, do nothing. if (strlen($month) == 2) { //select date from $sqla="SELECT * WHERE datein LIKE '".$year."-".$month."'"; $resulta = mysql_query($sqla) or die(mysql_error()); $numa = mysql_num_rows($resulta); //select date to $sqlb="SELECT * WHERE datein LIKE '".$year."-".$month."'"; $resultb = mysql_query($sqlb) or die(mysql_error()); $numb = mysql_num_rows($resultb); } //if 1 character long add a "0" else { //select date from $sqla="SELECT * WHERE datein LIKE '".$year."-0".$month."'"; $resulta = mysql_query($sqla) or die(mysql_error()); $numa = mysql_num_rows($resulta); //select date to $sqlb="SELECT * WHERE datein LIKE '".$year."-".$month."'"; $resultb = mysql_query($sqlb) or die(mysql_error()); $numb = mysql_num_rows($resultb); } //if there are no records display this: if (($numa < 1) && ($numb < 1)) { echo "NO RESERVATIONS FOUND"; } //if there are records, display this: else { //?????????? } the issue that i am having is in the //?????????? area at the end. what i want is to have the code automatically distinguish duplicate names...there are 2 different queries here. one is searching for the checkin date, the other the checkout date. is there a way to compare the two and not duplicate them, but instead combine them? what i mean is this... a checkin might be on the 28th of the month,where the checkout might be on the 4th of the next...i need to be able to show this on a calendar and apply it. here is a link to the calendar any ideas are helpful...thanks. Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-605848 Share on other sites More sharing options...
Andy-H Posted August 2, 2008 Share Posted August 2, 2008 We can't view that as were not logged in... Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-605903 Share on other sites More sharing options...
ardyandkari Posted August 2, 2008 Author Share Posted August 2, 2008 sorry...forgot... here you go... username: test password : d Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-606313 Share on other sites More sharing options...
ardyandkari Posted August 11, 2008 Author Share Posted August 11, 2008 have added a logout feature and the ability to change usernames and passwords, and also add users. disabled the username/password change on the test db, but you will still get the feel. script checks to see if there is already the username in the db...kinda neat considering how little i know... any suggestions as to what to add? also, regarding neil.johnson's post...i understand what i have to do, just not how to implement it...haven't quite figured out arrays yet...will try when i get some spare time, but if anyone wants to give me a hint that would be much appreciated... thanks a lot and take a look at the program if you want. Quote Link to comment https://forums.phpfreaks.com/topic/116917-creating-a-reservation-system-in-over-my-head/#findComment-613441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.