PHP - Sql Date Range Query
Hi i have the following code Quote
$sql= "SELECT * FROM income WHERE month(date) between '04' and '12' and year(date) between 2020 and 2020"; This obviously selects all the information from April 2020 to December 2020
How do i change this to add a date as well for example if i wanted to display all the information from April 6th 2020 to December 5th 2020 ?
Similar TutorialsHi,
I can I include a date range criteria to query with in the following code? The date field in the table (t_persons) is IncidentDate.
$criteria = array('FamilyName', 'FirstName', 'OtherNames', 'NRCNo', 'PassportNo', 'Gender', 'IncidenceCountryID', 'Status', 'OffenceKeyword', 'AgencyID', 'CountryID', 'IncidenceCountryID' ); $likes = ""; $url_criteria = ''; foreach ( $criteria AS $criterion ) { if ( ! empty($_POST[$criterion]) ) { $value = ($_POST[$criterion]); $likes .= " AND `$criterion` LIKE '%$value%'"; $url_criteria .= '&'.$criterion.'='.htmlentities($_POST[$criterion]); } elseif ( ! empty($_GET[$criterion]) ) { $value = mysql_real_escape_string($_GET[$criterion]); $likes .= " AND `$criterion` LIKE '%$value%'"; $url_criteria .= '&'.$criterion.'='.htmlentities($_GET[$criterion]); } //var_dump($likes); } $sql = "SELECT * FROM t_persons WHERE PersonID>0" . $likes . " ORDER BY PersonID DESC";Kind regards. Why is this not working? Code: [Select] $result = mysql_query("SELECT * FROM contacts WHERE type = 'consumer' AND sent BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("-7 days"))."'") or die(mysql_error()); $numrows = mysql_num_rows($result); if($numrows < 0 ){ echo "No records found"; } The record that is stored in the sent column is like this "2011-11-03 14:42:12", so there is a record in there, but nothing is showing up. Can anyone see why? thanks in advance I am currently working on a date range script and wondering if anybody think of an easier way to do this, doing up to next 8 weeks? This one starts on a Sunday. I also need to do one starting on a Monday (will figure that one later) $thisweek = date("Y-m-d"); $week = date('w', strtotime($thisweek)); $date = new DateTime($thisweek); $firstWeek = $date->modify("-".$week." day")->format("M d"); $endWeek = $date->modify("+6 day")->format("M d"); echo $firstWeek." - "; echo $endWeek; $nextweek = date(("Y-m-d"), strtotime("+7 Days")); $week1 = date('w', strtotime($nextweek)); $date1 = new DateTime($nextweek); $firstWeek1 = $date1->modify("-".$week1." day")->format("M d"); $endWeek1 = $date1->modify("+6 day")->format("M d"); echo $firstWeek1." - "; echo $endWeek1;
Hello, I'm very disapointed because I don't know how do it this. I'm explain. I have a database with one input date_arrival and second date_departure. Two dates are saved in SQL format : 2014-03-02. After my SQL request to select all dates in database I'd like to add dates between date_arrival and date_departure and for each line. For example I have date_arrival date_departure line 1 : 2014-02-01 2014-02-05 line 2 : 2014-02-10 2014-02-15 In fact at the end, I have to send the result like this (with JSON) : ["2014-02-01","2014-02-02","2014-02-03","2014-02-04","2014-02-05","2014-02-10","2014-02-11","2014-02-12","2014-02-13","2014-02-14","2014-02-15"] Can you give me some help to add intermediates values in an array ? Thx I am working on a report generation. Here I need to count the number of months involved in the selected date range. I need to apply the monthly charges accordingly. Example: If the user selects 25-08-2011 to 03-10-2011, it should return 3 as the number of months. Yes, the number of days are less than 60 but still the date range is spread across 3 months. Any solution.. Please. Girish I'm trying to wrap my head around how i should go about doing this. I have two dates...2011-05-03 and 2011-05-08. I want to write a function that creates an array of the days that consist of that date range. So say something like Code: [Select] <?php $start = "2011-05-03"; $end = "2011-05-08"; function get_days($start, $end) { //code to get the days } echo get_days($start, $end); //hopefully produce something like... $day['1'] = "2011-05-03"; $day['2'] = "2011-05-04"; $day['3'] = "2011-05-05"; $day['4'] = "2011-05-06"; $day['5'] = "2011-05-07"; $day['6'] = "2011-05-08"; anybody know any idea how to do something like this? Pretty sure i'm going to need the mktime() function to account for ranges going across months and years. Setup: Mysql table 1: acct#, client name, status(active/not active), Starting balance, ending balance Mysql table 2: acct#, invoice amount, invoice date, total how do i select all customers that are Active, and the starting balance != ending balance and then get the total for all invoices for that customer where the invoice date is between 2010-01-01 and 2010-03-01 Basically my out put needs to look like this. Customer name, Total of all invoices for customer john doe, $10,564.21 Susy Scott, $158.02 Bang Head, $837,294.85 Customer can have multiple invoices within the given date range. But I only need the total for all the invoices for each customer added up and echo'ed. Quickness is also a factor on the query and echo. Thank you for your valuable time. Hello, Im trying to work out some code. On my site between Thursday 12th July and Sunday 15th July between the hours of 22:00 and 23:00 I want to display some code. I've done this so far, but am having trouble. Anyone please help? $the_date = date("H:i:s"); $timesep = explode(":",$the_date); // $hour = $timesep[0]; if (($the_date > 2010-08-12 && < 2010-08-15) && ($hour >= 22) && ($hour <= 23)) { //Code } Hi all
This is a one I've spent DAYS on and can't figure out :-\ This is for a wedding venue and their pricing schedule is divided into low, medium, high and very high seasons. I.e. low season runs from 8 Jan 16 to 28 Feb 16, medium runs from 4 Mar 16 to 20 Mar 16, etc. The database for this is laid out as attached. I would like people to be able to enter their arrival and departure date and for it to be able to choose which seasons the date range falls under. I.e. If they stay 8 to 12 Jan, that's no problem to calculate and falls under LOW season. However, if they stay 27 Feb to 10 Mar, this falls under both LOW and MID seasons, with the majority of the stay in the MID season (which we'd price with but can use PHP to choose the 'highest' season from the array). I'm a bit stumped on this one so any help is hugely appreciated! I'm sure it's something quite simple that I'm missing. Attached Files Screen Shot 2015-01-10 at 16.58.17.png 146.3KB 0 downloads I'm trying to do the following PHP. I have written it in English if (today's date) => date1 AND <= date2 then {display image1} elseif (today's date) => date3 AND <= date4 then {display image2} else {display image 13} There are 24 fixed dates and 13 fixed images. I have tried using combinations of strtotime(), replacing the date value with variables, hard coding the dates within the program. I don't seem to be able to get any combination to work properly. I'm sure it's just a syntax error but I can't see it. When I've searched the web all the answers I've found relate to dates within databases but as I only have 24 dates it seems a bit of overkill. I would appreciate any pointers to the correct method I might be able to use. The dates need only a day and month as I would like this to repeat year after year. <?php $today = strtotime(date('d-m')); if (strtotime($today) >= strtotime('28-10') && strtotime($today) <= strtotime('24-11')) {echo "<div>image1</div>";} elseif (strtotime($today) >= strtotime('25-11') && strtotime($today) <= strtotime('22-12')) {echo "<div>image2</div>" ;} elseif (strtotime($today) >= strtotime('23-12') && strtotime($today) <= strtotime('24-02')) {echo "<div>image3</div>" ;} else {echo "<div>image13</div>";} ?> The result I get from this is image1 appears on the web page but I would expect image3 as today is 22-01 Thank you in advance. Andrew Hello,
I've been going about reading different posts on here and other forums but so far I haven't been able to come across something that works for my purpose so after all the reading I thought I'd finally just ask. I'm rather new at php/sql queries so please bare with me.
First what I'm trying to accomplish.
I need a form with several fields (options) to fetch information from a table that will then display the results based on the options selected.
- from date
- to date
- employee name
- department
- branch
- product line
In other words, the purpose is to be able to choose a date range (from one day to up to a year or more) and then to be able to choose either ONE employee name to view statistics invididually from a given department and branch or to select a department to view all the statistics for everyone under that given department and/or brach and/or product line.
Now the tricky part is that besides fetching the records, calculations need to be made before the records are displayed and that part right here is what is giving me a huge headache.
This is the query that I have.
SELECT report_daily_id, report_date, emp_id, emp_fullname, emp_dept, emp_branch prod_line calls, tk_time, hld_time, ac_time, tran_calls, work_time, tran_rate, ah_time FROM daily_report GROUP BY emp_id, emp_fullname, emp_branch, emp_dept, prod_lineThe calculations based on the date range and one or more of the other options need to give me the following results. SUM(calls) AS 'Total Calls' SUM(tk_time) / SUM(calls) AS 'Talk Time' SUM(hld_time) / SUM(calls) AS 'Held Time' SUM(ac_time) / SUM(calls) AS 'AC Time' SUM(tran_calls) AS 'Total Trans' SUM(tran_calls) / SUM(calls) AS 'Tran Rate' SUM(ah_time) / SUM(calls) AS 'AH Time'I don't know how else to explain myself past this point but if you have any questions, perhaps I can answer it and give more details. Thank you, Hi. Im searching for a way to enter multiple records at once to mysql databased on a date range. Lets say i want to insert from date 2010-11-23 to date 2010-11-25 a textbox with some info and the outcome could look in database like below. ---------------------------------------------------------- | ID | date | name | amount | ----------------------------------------------------------- | 1 | 2010-11-23 | Jhon | 1 | | 2 | 2010-11-24 | Jhon | 1 | | 2 | 2010-11-25 | Jhon | 1 | ----------------------------------------------------------- The reason i need the insertion to be like this is because if quering by month and by user to see vacation days then vacations that start in one month and end in another month can be summed by one month. If its in one record then it will pop up in both months. Help is really welcome. I have the week date range displaying the week range from sunday - saturday
$current_dayname = date("0"); // return sunday monday tuesday etc. echo $date = date("Y-m-d",strtotime('last sunday')).'to'.date("Y-m-d",strtotime("next saturday")); Which outputs in the following format 2015-01-25to2015-01-31 However, when I press next or previous, the dates don't change. <?php $year = (isset($_GET['year'])) ? $_GET['year'] : date("Y"); $week = (isset($_GET['week'])) ? $_GET['week'] : date('W'); if($week > 52) { $year++; $week = 1; } elseif($week < 1) { $year--; $week = 52; } ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 52 ? 1 : 1 + $week).'&year='.($week == 52 ? 1 + $year : $year); ?>">Next Week</a> <!--Next week--> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 1 ? 52 : $week -1).'&year='.($week == 1 ? $year - 1 : $year); ?>">Pre Week</a> <!--Previous week--> <table border="1px"> <tr> <td>user</td> <?php if($week < 10) { $week = '0'. $week; } for($day= 1; $day <= 7; $day++) { $d = strtotime($year ."W". $week . $day); echo "<td>". date('l', $d) ."<br>". date('d M', $d) ."</td>"; } ?> </tr> </table> I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy Hi everyone I have a database with table containing my news it has a `start_date` field and a `end_date` field and I store dates as YYYY-MM-DD I have a PHP script on my webpage which I have a date set on it, such as $date = '2010-10-23' What QUERY would I need to run to return all rows which the date defined falls between the start and end date Any help would be great I tried WHERE `start_date` >= '2010-09-13' AND `end_date` <= '2010-09-13' but that doesn't seem to work // Nav Tabs $query = "select DISTINCT YEAR(sold_date) FROM Sold"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $year = substr($row['sold_date'], 0, -6); $navTab .= '<a class="miniTabOn" href="index.php?date='.$year.'">'.$year.'</a>'; } I am trying to create a link for each year of items in my database, yet the text is not showing up... The "nav tab" is, because I can see the background image from the class="miniTabOn". Can anyone spot an error? I'm creating a line graph using ChartJs. I wanted to display my data according to the month selected by the user. For example, if the user select "2021-03" all the order that is made in the month of March will be plotted in the graph. It works well for the current month, but it does not work for the selected month. I use Ajax to get the data but i do not know why my graph does not shown when i click on my `loadchart();` button. Can anyone enlighten me how can i do it? Because i do not know what mistake did i made here. Any kind of explanation will be appreciated. Thanks!
This is the where i place my `loadchart()` button and also the javascript to plot the graph. <div class="col-md-12 form-group"> <div class="card" style="box-shadow: 0 0 8px rgb(0,0,0,0.3)"> <div class="row"> <div class="col col-lg-1"></div> <div class="col-2 my-auto"> <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>"> </div> <div class="col-2 my-auto"> <button type="button" class="btn btn-info" onclick="loadchart();"> <i class="nc-icon nc-zoom-split"></i> </button> </div> </div> <div id="loadchart"> <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (Current Month)</h6> <div class="card-body"> <canvas id="attChart"></canvas> </div> </div> </div> </div> </div> </div> </div> </div> <!-- Chart JS --> <script src="./assets/js/plugins/chartjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <?php $days = array(); $gross_sales = array(); $average_sales = array(); $type = CAL_GREGORIAN; $month = date('n'); // Month ID, 1 through to 12. $year = date('Y'); // Year in 4 digit 2009 format. $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days //loop through all days for ($i = 1; $i <= $day_count; $i++) { $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH(NOW()) AND YEAR(order_datetime) = YEAR(NOW()) AND order_status = 5 "; $query = $conn->query($sql); $total = $query->num_rows; $row = $query->fetch_assoc(); if($row['purchase_price'] != 0) { $gross_sales[] = $row['purchase_price']; } else if ($row['purchase_price'] == 0 && $i <= date('d')) { $gross_sales[] = 0; } $average_sales[] = $row['purchase_price'] / $day_count; $day = $i.'/'.$month; //format date array_push($days, $day); } $days = json_encode($days); $daily_gross_sales = json_encode($gross_sales); $average_gross_sales = json_encode($average_sales); ?> <script> const colors = { colorcode: { fill: '#51cbce', stroke: '#51cbce', }, }; var ctx2 = document.getElementById("attChart").getContext("2d"); const attChart = new Chart(ctx2, { type: 'line', data: { labels: <?php echo $days; ?>, //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], datasets: [{ label: "Gross Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: colors.colorcode.stroke, borderColor: colors.colorcode.stroke, pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $daily_gross_sales; ?>, showLine: true }, { label: "Average Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: '#FF0000', borderColor: ' #FF0000 ', pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $average_gross_sales; ?>, showLine: true } ] }, options: { responsive: true, // Can't just just `stacked: true` like the docs say scales: { yAxes: [{ stacked: false, gridLines: { display: true, color: "#dee2e6" }, ticks: { stepSize: 100000, callback: function(tick) { return 'RM'+tick.toString(); } } }], xAxes: [{ stacked: false, gridLines: { display: false }, }] }, animation: { duration: 3000, }, legend:{ display: false, } } }); </script> This is my AJAX method <script type="text/javascript"> function loadchart() { $('#spin1').show(); var month= $('#month').val(); //alert(date); var data = { // create object month: month, } $.ajax({ method:"GET", data:data, url:"includes/loadchart.php", success:function(data) { $('#loadchart').html(data); } }); } </script> This is where i use to load the graph whenever a month is selected. (loadchart.php) <?php include '../session.php'; if(isset($_GET['month'])) { $months = $_GET['month']; ?> <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (<?php echo $months ?>)</h6> <div id="loadchart" class="card-body"> <canvas id="attChart"></canvas> </div> </div> </div> </div> </div> </div> </div> <!-- Chart JS --> <script src="./assets/js/plugins/chartjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <?php $days = array(); $gross_sales = array(); $average_sales = array(); $type = CAL_GREGORIAN; // Gregorian (localized) calendar $month = date('n'); // Month ID, 1 through to 12. $year = date('Y'); // Year in 4 digit 2009 format. $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days //loop through all days for ($i = 1; $i <= $day_count; $i++) { $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH('".$months."') AND YEAR(order_datetime) = YEAR('".$months."') AND order_status = 5 "; $query = $conn->query($sql); $total = $query->num_rows; $row = $query->fetch_assoc(); if($row['purchase_price'] != 0) { $gross_sales[] = $row['purchase_price']; } else if ($row['purchase_price'] == 0 && $i <= date('d')) { $gross_sales[] = 0; } $average_sales[] = $row['purchase_price'] / $day_count; $day = $i.'/'.$month; //format date array_push($days, $day); } $days = json_encode($days); $daily_gross_sales = json_encode($gross_sales); $average_gross_sales = json_encode($average_sales); ?> <script> const colors = { colorcode: { fill: '#51cbce', stroke: '#51cbce', }, }; var ctx2 = document.getElementById("attChart").getContext("2d"); const attChart = new Chart(ctx2, { type: 'line', data: { labels: <?php echo $days; ?>, //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], datasets: [{ label: "Gross Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: colors.colorcode.stroke, borderColor: colors.colorcode.stroke, pointHighlightStroke: colors.colorcode.stroke, borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $daily_gross_sales; ?>, showLine: true }, { label: "Average Sales: RM", fill: true, //backgroundColor: colors.colorcode.fill, pointBackgroundColor: '#FF0000', borderColor: ' #FF0000 ', pointHighlightStroke: '#FF0000', borderCapStyle: 'dot', pointRadius: 5, pointHoverRadius: 5, pointStyle: 'dot', data: <?php echo $average_gross_sales; ?>, showLine: true } ] }, options: { responsive: true, // Can't just just `stacked: true` like the docs say scales: { yAxes: [{ stacked: false, gridLines: { display: true, color: "#dee2e6" }, ticks: { stepSize: 100000, callback: function(tick) { return 'RM'+tick.toString(); } } }], xAxes: [{ stacked: false, gridLines: { display: false }, }] }, animation: { duration: 3000, }, legend:{ display: false, } } }); </script> <?php } ?> Edited April 27 by sashavalentina Hello, I am doing a hotel reservation website.First am getting the checkin (arrival) and Check out(Departure) date from user.Then in next from i fetch both this values using POST method and store it in variable $arrival and $departure and then am formattind the date as i want it in the form YYYY-MM-DD(My SQL). Then am using the value of variable $arr and $dep in a query to fetch the records from DB but it is giving error.But when i do it in Hard code way I mean directly inserting the date in query it is running smmothly.Please help!!!! Am using Xampp 2.5 Heres my code... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ROOMS</title> <?php $arrival = $_POST['start']; $departure = $_POST['end']; $adults=6; $child=2; $room_id=101; function changeFormatDate($cdate){ list($day,$month,$year)=explode("/",$cdate); return $year."-".$month."-".$day; } // $arr="'".$arr."'"; $arr= changeFormatDate($arrival); //settype($arr, "string"); // $timestamp=strtotime($arr1); // $arr=date("Y-m-d",$timestamp); $dep= changeFormatDate($departure); // $timestamp=strtotime($dep1); // $dep=date("Y-m-d",$timestamp); ?> <style type="text/css"> <!-- .style2 { font-size: 12px; font-weight: bold; } --> </style> </head> <body> <!-- TOP --> <div id="top1"><a href="index.php"></a></div> <div id="top"> <ul class="menu"> <li class="home"><a href="index.php">Home</a></li> <li class="about"><a href="about.php">About</a></li> <li class="contacts"><a href="contact.php">Contacts</a></li> <li class="renting"><a href="gallery.php">GALLERY</a></li> <li class="selling"><a href="rates.php">RATES</a></li> </ul> </div> <!-- HEADER --> <!-- CONTENT --> <div id="content"> <div id="leftPan"> <div id="services"> <h2>RESERVATION DETAILS </h2> <p> <ul> Check In Date :<?php echo $arrival; ?><br /> Check Out Date :<?php echo $departure; ?> <br /> </ul> </p> </p> </div> </div> <div id="featured"><br /> <div> <form action="personnalinfo.php" method="post" onsubmit="return validateForm()" name="room"> <input name="start" type="hidden" value="<?php echo $arrival; ?>" /> <input name="end" type="hidden" value="<?php echo $departure; ?>" /> <input name="rooms" id="rooms" type="hidden" /> <input name="adult" type="hidden" value="<?php echo $adults; ?>" /> <input name="child" type="hidden" value="<?php echo $child; ?>" /> </div> <table bgcolor="white" border="1" width="100%" style="float:left;table-layout:fixed" cellpadding="10" cellspacing="0" > <col width="70%"> <tr> <th colspan="2" bgcolor="white"><h2><font color=maroon>Room Type</font></h2></th> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/apt.jpg" style="float:left" /> </br> <div style="margin-top:120px;margin-left:5px"> <img src="img1/apt1.jpg" /> <img src="img1/apt2.jpg" /> <img src="img1/apt3.jpg" /> </div> </td> <td> <h3>Appartment</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 5,000.00</span><br /> <a> Apparment in HOTEL BELLA has 2 Rooms with connecting door.It can accomodate 4 Adult and 2 children. And are located on Beach side to give you comfort and a panoramic view so that you can have a luxury accommodation.<br> *Sitting area <br>*jacuzzi shower</br> *Large terrace overlooking the sea *Jacuzzi *Light therapy *Air treatment <a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i1.jpg" /> </td> </tr> <tr> <td align="left" > <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("single")?> </td> </tr> </table> </td> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/double.jpg" style="float:left" /> </br> <div id="featured"> <img src="img1/double1.jpg" /> <img src="img1/double2.jpg" /> <img src="img1/double3.jpg" /> </div> </td> <td> <h3>Double</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 3,000.00</span><br /> <a>Double rooms in HOTEL BELLA has Double bed. And can accomodate 2 Adults and 2 kids. It is comfortable and pleasant, with balcony and sea view. We hope that you will enjoy your summer holidays in Bella. BASIC: Telephone. Satellite TV. Safety Deposit Box. Mini Bar - Refrigerator. Air condition. Shower with or without cabin. Hair Dryer. Balcony.<a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i2.jpg" /> </td> </tr> <tr> <td align="left"> <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("double")?> </td> </tr> </table> </td> </tr> <tr> <td> <table border="0" style="float:left;table-layout:fixed" width="100%"> <col width="55%"> <tr> <td valign="top"> <img src="img1/single.jpg" style="float:left" /> </br> <div id="featured"> <img src="img1/single1.jpg" /> <img src="img1/single2.jpg" /> <img src="img1/single3.jpg" /> </div> </td> <td> <h3>Single</h3> <br> <span class="price">Price:</span> <span class="number">Rs. 2,000.00</span><br /> <a> Single Room in HOTEL BELLA has single bed, bathroom.Can accomodated single person. is comfortable and pleasant, with balcony and sea view Telephone Satellite TV Safety Deposit Box Mini Bar - Refrigerator Air condition Hair Dryer <a href="#">more...</a></p><br /> </td> </tr> </table> </td> <td valign="top"> <table border=0 width="100%" cellspacing="10"> <tr> <td align="left"> <label><h3>People : </h3></label> </td> <td align="right"> <img src="img1/i3.jpg" /> </td> </tr> <tr> <td align="left"> <label><h3>Rooms : </h3></label> </td> <td align="right" > <?php gen_options("apartment")?> </td> </tr> </table> </td> </tr> </table> <div style="margin-top:1200px;margin-left:5px;text-align:right;"> <input type="image" src="img1/book.jpg" name="book" value="submit"/> </div> <?php function gen_options($type) { // print "$id"; // print "$type"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("hotel", $con); $count=0; $result = mysql_query("SELECT * FROM rooms where type='$type'"); while($row = mysql_fetch_array($result)) { $a=$row['room_no']; //print "$a"; // $query1 = mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and status='active'"); // $query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='2012-05-11' AND departure>='2012-05-11')OR(arrival<='2012-05-13' AND departure>='2012-05-13'))"); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival BETWEEN '2012-05-11' AND '2012-05-13') or (departure BETWEEN '2012-05-11' AND '2012-05-13'))"); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='$arr' AND departure>='$arr')OR(arrival<='$dep' AND departure>='$dep'))"); $quer=sprintf("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival<='%s' AND departure>='%s')OR(arrival<='%s' AND departure>='%s'))",$arr,$arr,$dep,$dep); $query=mysql_query($quer); //$query=mysql_query("SELECT count(*) FROM `room_inventory` WHERE room_no='$a' and ((arrival BETWEEN '$arr' AND '2012-05-13') or (departure BETWEEN '$arr' AND '2012-05-13'))"); $r=mysql_fetch_array($query); $v=$r['count(*)']; // print "$v"; if($v==0) { $count++; // print "$count"; } } echo '<select name="room1" class="ed" id="r1">'; for($i=0;$i<=$count;$i++) { echo '<option>'.$i.'</option>'; } echo '</select>'; mysql_close($con); } // echo "$arrival\n"; // print "$departure\n"; echo "$arr"; echo "$dep"; // echo date_format($arrival, 'Y-m-d'); ?> <input type="hidden" name="result" id="result" /> </form> </div> <div class="clear"></div> </div> <!-- FOOTER --> <div id="footer"> <p><a href="index.php">HOME</a> |<a href="about.php"> ABOUT US </a>|<a href="contact.php"> CONTACTS </a>|<a href="gallery.php"> GALLERY </a>|<a href="rates.php"> ROOM RATES </a></p> </div> </body> </html> |