Jump to content

detect months


searls03

Recommended Posts

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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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());
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.