searls03 Posted November 21, 2011 Share Posted November 21, 2011 Ok, so I have a code that looks like so: <script type="text/javascript"> var ng_config = { assests_dir: 'ng/assets/' // the path to the assets directory } </script> <script type="text/javascript" src="ng/ng_all.js"></script> <script type="text/javascript" src="ng/components/calendar.js"></script> <script type="text/javascript"> var my_cal; ng.ready(function(){ // creating the calendar var my_cal = new ng.Calendar({ input: 'enddate', start_date: 'year - 1', // the start date (default is today) display_date: ng.get('startdate').value, // the display date (default is start_date) server_date_format: 'm/d/Y' // changing the server date format for a specific calendar. }); }); var my_cal1; ng.ready(function(){ // creating the calendar my_cal1 = new ng.Calendar({ input: 'startdate', start_date: 'year - 1', // the start date (default is today) display_date: new Date(), // the display date (default is start_date) server_date_format: 'm/d/Y' // changing the server date format for a specific calendar. }); }); how do I detect the months that pass between the two dates that are selected using a popup calendar using php so that my register page know which month to display the event under. Does this make sense? Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/ Share on other sites More sharing options...
vbnullchar Posted November 21, 2011 Share Posted November 21, 2011 is this a javascript question? this might help http://www.dreamincode.net/code/snippet1542.htm Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1289923 Share on other sites More sharing options...
searls03 Posted November 22, 2011 Author Share Posted November 22, 2011 yes, sort of a javascript question. I would like to know how to do what I need in PHP though....that is why I posted here, that way I can set it up to submit easier after it is in PHP. no. I need the system to recognize the first number of the date so the 11 in 11/12/2011 for example. I think there is a way to do this using the date function but I need to know how I could get it to just recognize the one number......but also all numbers inbetween......so 11/12/2011 and 1/1/2011 so it would find 11, 12, and 1 so that it shows under november, december, and january. Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290585 Share on other sites More sharing options...
requinix Posted November 22, 2011 Share Posted November 22, 2011 You can just explode the date string by slashes. Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290605 Share on other sites More sharing options...
Psycho Posted November 22, 2011 Share Posted November 22, 2011 This could probably be more efficient, but it works for what you want. function getListOfMonths($startDate, $endDate) { //Get timestamps for the first of each date passed $startDateTS = strtotime($startDate); $endDateTS = strtotime($endDate); //Some basic validation if(!$startDateTS || !$endDateTS || ($startDateTS > $endDateTS)) { return false; } //Get month and year vars $startMonth = date('m', $startDateTS); $startYear = date('Y', $startDateTS); $endMonth = date('m', $endDateTS); $endYear = date('Y', $endDateTS); //Normalize the dates to 12noon on the 1st of the month $startDateTS = mktime(12, 0, 0, $startMonth, 1, $startYear); $endDateTS = mktime(12, 0, 0, $endMonth, 1, $endYear); //Get the months between (inclusive) $months = array(); while($startDateTS <= $endDateTS) { $months[] = date('m-Y', $startDateTS); $startDateTS = mktime(12, 0, 0, ++$startMonth, 1, $startYear); } return $months; } $dates = getListOfMonths('11/12/2011', '1/1/2012'); print_r($dates); Output: Array ( [0] => 11-2011 [1] => 12-2011 [2] => 01-2012 ) Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290612 Share on other sites More sharing options...
searls03 Posted November 23, 2011 Author Share Posted November 23, 2011 how could I insert these into my database? month1...month2....etc all the way to month12? how do I do this with the array? Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290824 Share on other sites More sharing options...
searls03 Posted November 23, 2011 Author Share Posted November 23, 2011 or is there a better way than doing it month1-12? Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290828 Share on other sites More sharing options...
searls03 Posted November 23, 2011 Author Share Posted November 23, 2011 so I have decided to make a table that will link with event name using an array to make it insert multiple months. is this how I would do it? </form> <?php if(isset($_POST['save'])) { $event = $_POST['event']; $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; $description = $_POST['description']; $location = $_POST['location']; function getListOfMonths($startDate, $endDate) { //Get timestamps for the first of each date passed $startDateTS = strtotime($startDate); $endDateTS = strtotime($endDate); //Some basic validation if(!$startDateTS || !$endDateTS || ($startDateTS > $endDateTS)) { return false; } //Get month and year vars $startMonth = date('m', $startDateTS); $startYear = date('Y', $startDateTS); $endMonth = date('m', $endDateTS); $endYear = date('Y', $endDateTS); //Normalize the dates to 12noon on the 1st of the month $startDateTS = mktime(12, 0, 0, $startMonth, 1, $startYear); $endDateTS = mktime(12, 0, 0, $endMonth, 1, $endYear); //Get the months between (inclusive) $months = array(); while($startDateTS <= $endDateTS) { $months[] = date('m-Y', $startDateTS); $startDateTS = mktime(12, 0, 0, ++$startMonth, 1, $startYear); } return $months; } $title1 = $_POST['title1']; $title2 = $_POST['title2']; $title3 = $_POST['title3']; $title4 = $_POST['title4']; $title5 = $_POST['title5']; $title6 = $_POST['title6']; $title7 = $_POST['title7']; $title8 = $_POST['title8']; $date1 = $_POST['date1']; $date2 = $_POST['date2']; $date3 = $_POST['date3']; $date4 = $_POST['date4']; $date5 = $_POST['date5']; $date6 = $_POST['date6']; $date7 = $_POST['date7']; $date8 = $_POST['date8']; $subevent1 = $_POST['subevent1']; $subevent2 = $_POST['subevent2']; $subevent3 = $_POST['subevent3']; $subevent4 = $_POST['subevent4']; $subevent5 = $_POST['subevent5']; $subevent6 = $_POST['subevent5']; $subevent7 = $_POST['subevent6']; $subevent8 = $_POST['subevent7']; $price1 = $_POST['price1']; $price2 = $_POST['price2']; $price3 = $_POST['price3']; $price4 = $_POST['price4']; $price5 = $_POST['price5']; $price6 = $_POST['price6']; $price7 = $_POST['price7']; $price8 = $_POST['price8']; $month_num = $_POST['month_num']; $day = $_POST['day']; $year = $_POST['year']; $shutoff = $_POST['shutoff']; if(!get_magic_quotes_gpc()) { $event = addslashes($event); $startdate = addslashes($startdate); $enddate = addslashes($enddate); $description = addslashes($description); $location = addslashes($location); $month = addslashes($month); $title1 = addslashes($title1); $title2 = addslashes($title2); $title3 = addslashes($title3); $title4 = addslashes($title4); $title5 = addslashes($title5); $title6 = addslashes($title6); $title7 = addslashes($title7); $title8 = addslashes($title8); $date1 = addslashes($date1); $date2 = addslashes($date2); $date3 = addslashes($date3); $date4 = addslashes($date4); $date5 = addslashes($date5); $date6 = addslashes($date6); $date7 = addslashes($date7); $date8 = addslashes($date8); $subevent1 = addslashes($subevent1); $subevent2 = addslashes($subevent2); $subevent3 = addslashes($subevent3); $subevent4 = addslashes($subevent4); $subevent5 = addslashes($subevent5); $subevent6 = addslashes($subevent6); $subevent7 = addslashes($subevent7); $subevent8 = addslashes($subevent8); $price1 = addslashes($price1); $price2 = addslashes($price2); $price3 = addslashes($price3); $price4 = addslashes($price4); $price5 = addslashes($price5); $price6 = addslashes($price6); $price7 = addslashes($price7); $price8 = addslashes($price8); $month2 = addslashes($month2); $month_num = addslashes($month_num); $year = addslashes($year); $day = addslashes($day); } include 'config.php'; include 'opendb.php'; $query = "INSERT INTO Registration (event, startdate, enddate, description, location, month, title1, title2, title3, title4, title5, title6, title7, title8, date1, date2, date3, date4, date5, date6, date7, date8, subevent1, subevent2, subevent3, subevent4, subevent5, subevent6, subevent7, subevent8, price1, price2, price3, price4, price5, price6, price7, price8, month2, shutoff) VALUES ('$event', '$startdate', '$enddate', '$description', '$location', '$month', '$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$date1', '$date2', '$date3', '$date4', '$date5', '$date6', '$date7', '$date8', '$subevent1', '$subevent2', '$subevent3', '$subevent4', '$subevent5', '$subevent6', '$subevent7', '$subevent8', '$price1', '$price2', '$price3', '$price4', '$price5', '$price6', '$price7', '$price8', '$month2', '$shutoff')"; mysql_query($query) or die(mysql_error()); foreach ($_POST[$months] as $key => $value){ $query1 = "INSERT INTO register months (month, event) VALUES ('$value', '$event')"; mysql_query($query1) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290836 Share on other sites More sharing options...
searls03 Posted November 23, 2011 Author Share Posted November 23, 2011 if that's the way.....it doesn't post to the register months table Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1290839 Share on other sites More sharing options...
searls03 Posted November 26, 2011 Author Share Posted November 26, 2011 did that make sense as to what I would like to do? I would like to do it the array way where it will insert into the database so that it will have basically unlimited months. does this make sense? please help.... Quote Link to comment https://forums.phpfreaks.com/topic/251517-detect-months/#findComment-1291378 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.