redarrow Posted May 1, 2006 Share Posted May 1, 2006 Advance thank you.I would like a way to get a date month year pull down dox for users to insert the date month and year they select inserted into the database.but i dont wont to use the old way using <seleect>option metod i wont the same effect but converting the date function.so that the select statement outputs from todays date month year from 01 to 31 and january to december and year from 2006 to 2008. Hope someone has done this and can help cheers.example but needs help cheers[code]<?$day=date("d");$month=date("m");$year=date("y");?><form metod="post" action=""><select name="day"><option name="day" value="<?echo$day?>">Day <?echo$day?></option></select><select name="month"><option name="month" value="<?echo$month?>">Month <?echo$month?></option></select><select name="year"><option name="year" value="<?echo$year?>">Year <?echo$year?></option></select><br><input type="submit" name="submit date"></form>[/code]i am so close.The above code prints in a select box todays day month yearBut i need to alter this code below to get the day from 0-31 month from 0-12 and year from 2006-2008[code]<?$day=date("d");$month=date("m");$year=date("y");?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 1, 2006 Author Share Posted May 1, 2006 I thort that this was correct to get a drop down box from 1-31 but its in a stright line please help cheers.[code]<option name="day" value="<?echo$day?>">Day <?for($day=1; $day<31; $day++){echo $day.'<br>';}?></option>[/code] Quote Link to comment Share on other sites More sharing options...
craygo Posted May 1, 2006 Share Posted May 1, 2006 Try This[code]<?$day=date("d");$month=date("m");$year=date("Y");?><form metod="post" action="<?=$_SERVER['PHP_SELF']?>"><select name="day"><?for($days=01;$days<32;$days++){?><option name="day" value="<?=$days?>">Day <?=$days?></option>';<?}?></select><select name="month"><?for ($months=1;$months<13;$months++){?><option name="month" value="<?=$months?>" <? if($months == $month){ echo "selected";} ?>>Month <?=$months?></option>';<?}?></select><select name="year"><?for($years=2006; $years<2010;$years++){?><option name="year" value="<?=$years?>" <? if($years == $year){ echo "selected";}?>>Year <?=$years?></option><?}?></select><br><input type="submit" name="submit date"></form>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 1, 2006 Author Share Posted May 1, 2006 Can you kindly point me in the correct way to getdatemonthyearas one varable to post as as $date_not_allowedcheers.and also if got time exsplain your code in deatail as learning cheers grate job 10/10example[code]$date_not_allowed=($date && $month && $year);$date_not_allowed=($_post["date_not_allowed"]);[/code] Quote Link to comment Share on other sites More sharing options...
craygo Posted May 1, 2006 Share Posted May 1, 2006 I'm not sure I get you on the date not allowed thing. Maybe explain a little more what you are trying to do would help. If you are looking to blacklist certain dates, I do not think you will able to do it in the selection part. You will be able to do it after it is submitted though, as long as you have a list or table with the values in it.[code]<?if(isset($_GET['submit'])){$year = $_GET['year'];$month = $_GET['month'];$day = $_GET['day'];$selected_date = date("Y-m-d", strtotime("$year-$month-$day"));[/code]Now you can just pull a query and compare it against $selected_dateAs far as code goes:This pretty easy, get seperate day, month and year values:[code]<?$day=date("d");$month=date("m");$year=date("Y");?>[/code]This loops through the days, months, and years starting at 1 and going to the desired end, The second parameter in the loop (<) will not give you that value, only what is below it. So when using the loop always use a value one above what you want.[code]<select name="day"><?for($days=01;$days<32;$days++){?><option name="day" value="<?=$days?>" <? if($days == $day){ echo "selected";}?>>>Day <?=$days?></option>';<?}?></select>[[/code]This code is used in all to select the current day, month or year. It basically says if your $years(loop value) is equal to $year(your current day, month or year) then mark that value as the selected one.[code]<? if($years == $year){ echo "selected";}?>>[/code]Hope that helpsRay Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 1, 2006 Author Share Posted May 1, 2006 i need to get the date month and year as one into the database as one field under $date_not_allowed but how cheers, and thank you for your response and explenation cheers. Quote Link to comment Share on other sites More sharing options...
craygo Posted May 1, 2006 Share Posted May 1, 2006 Just use $selected_date in the example I gave above[code]$year = $_GET['year'];$month = $_GET['month'];$day = $_GET['day'];$date_not_allowed = date("Y-m-d", strtotime("$year-$month-$day"));[/code]if the date was 01/01/2007 the above example will output 2007-01-01.Now just insert it into your tableRay Quote Link to comment 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.