hi all,
i have two dropdown boxes in which i have to insert dates in first boxes from 1-31 and in second box i have numbers from 1-15. when i click on date1 and select 3 in second box
i should get 3 rows from date 1-3
and i have a doubt if its feb then we should get only 28 numbers i tried but didn`t get it,
any ideas:idea:
thank u in advance
praveen_dusari 11 Posting Whiz in Training
langsor
I do believe this has all the pieces you are looking for ... dates are a bit tricky to work with.
<?php
// PART ONE
// creating a drop down with only the days in this month
$today = new DateTime();
$days = $today->format('t');
print "<select name=\"days\">\n";
for ( $i = 1; $i <= $days; $i ++ ) {
print " <option value=\"$i\">$i</option>\n";
}
print "</select>\n";
print <<<ENDINPUT
<select name="stay">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="">...</option>
</select>
<br />
ENDINPUT;
// PART TWO
// parsing the input
$day = $_POST['days'];
$for = $_POST['stay'];
$day = 12; // for testing
$for = 4; // for testing
$today = $today = new DateTime();
$year = $today->format('Y');
$month = $today->format('n');
$delta = new DateTime( "$year-$month-$day" );
$omega = new DateTime( "$year-$month-$day" );
$omega->modify( "+$for day" );
while ( ( $delta->format('Ymd') + 0 ) < ( 0 + $omega->format('Ymd') ) ) {
// see this page for all available date formats
// http://us3.php.net/manual/en/function.date.php
print $delta->format( 'F d Y' )."<br>\n"; // example code
$delta->modify( "+1 day" ); // REQUIRED CODE
}
?>
You should probably modify the days drop down to only display the days from the current day to the last day of the current month -- I'll leave that part to you so you get the hands-on experience. ;-)
Hope this helps
...
praveen_dusari 11 Posting Whiz in Training
thanks for reply. i am getting error cant initiate class, iam using php4 i think it will not support classes and oops :(
and i should get three rows like incrementing dates depending upon second dropdown box this is important iam tried with javascript but didn`t get it any help plz
thanks in advance
langsor
Yep, DAteTime() is PHP 5 (PHP 5 >= 5.1.0) as per the documentation.
The way I see it, you have two choices ...
1. Upgrade you PHP or have your server upgrade their PHP
2. Take a look at the older Date() functions in the documentation and try to do it some other way
http://www.php.net/manual/en/function.date.php
... I recommend the first choice personally.
Wish I could help more, but I'm in the middle of my own project tonight.
Good luck
Html source output form my code -- choosing four (4) days from second dropdown ...
<html>
<head>
</head>
<body>
<select name="days">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="stay">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="">...</option>
</select>
<br />
August 12 2008<br>
August 13 2008<br>
August 14 2008<br>
August 15 2008<br>
</body>
</html>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.