SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How Can I Change The Time Format From 24 Hour To 12am and 12pm

    I have downloaded the calendar script from kubelabs.com and by default it shows the time format in a 24 hour mode. I am wanting to change that to 12am and 12pm. Can someone take a peek at the code below and see how to change it? I am clueless.


    Here is the index.php page:
    PHP Code:
    <?
    require_once("includes/config.php");

    if(!isset(
    $installed))
    {
        
    header("Location: install.php");
        exit;
    }
    else
    {
        if(
    file_exists('install.php'))
        {
            
    header("Location: install.php");
            exit;
        }
    }

    $db_connection mysql_connect ($DBHost$DBUser$DBPass) OR die (mysql_error());  
    $db_select mysql_select_db ($DBName) or die (mysql_error());
    $db_table $TBL_PR "events";

    function 
    getmicrotime(){ 
        list(
    $usec$sec) = explode(" ",microtime()); 
        return ((float)
    $usec + (float)$sec); 


    $time_start getmicrotime();

    IF(!isset(
    $_GET['year'])){
        
    $_GET['year'] = date("Y");
    }
    IF(!isset(
    $_GET['month'])){
        
    $_GET['month'] = date("n")+1;
    }

    $month addslashes($_GET['month'] - 1);
    $year addslashes($_GET['year']);

    $query "SELECT event_id,event_title,event_day,event_time FROM $db_table WHERE event_month='$month' AND event_year='$year' ORDER BY event_time";
    $query_result mysql_query ($query);
    while (
    $info mysql_fetch_array($query_result))
    {
        
    $day $info['event_day'];
        
    $event_id $info['event_id'];
        
    $events[$day][] = $info['event_id'];
        
    $event_info[$event_id]['0'] = substr($info['event_title'], 08);;
        
    $event_info[$event_id]['1'] = $info['event_time'];
    }

    $todays_date date("j");
    $todays_month date("n");

    $days_in_month date ("t"mktime(0,0,0,$_GET['month'],0,$_GET['year']));
    $first_day_of_month date ("w"mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));
    $first_day_of_month $first_day_of_month 1;
    $count_boxes 0;
    $days_so_far 0;

    IF(
    $_GET['month'] == 13){
        
    $next_month 2;
        
    $next_year $_GET['year'] + 1;
    } ELSE {
        
    $next_month $_GET['month'] + 1;
        
    $next_year $_GET['year'];
    }

    IF(
    $_GET['month'] == 2){
        
    $prev_month 13;
        
    $prev_year $_GET['year'] - 1;
    } ELSE {
        
    $prev_month $_GET['month'] - 1;
        
    $prev_year $_GET['year'];
    }



    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>PHPCalendar</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="images/cal.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    </head>

    <body>
    <div align="center"><span class="currentdate"><? echo date ("F Y"mktime(0,0,0,$_GET['month']-1,1,$_GET['year'])); ?></span><br>
      <br>
    </div>
    <div align="center"><br>
      <table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td><div align="right"><a href="<? echo "index.php?month=$prev_month&amp;year=$prev_year"?>">&lt;&lt;</a></div></td>
          <td width="200"><div align="center">
                
              <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
                <?
                
    for ($i 1$i <= 12$i++) {
                    
    $link $i+1;
                    IF(
    $_GET['month'] == $link){
                        
    $selected "selected";
                    } ELSE {
                        
    $selected "";
                    }
                    echo 
    "<option value=\"index.php?month=$link&amp;year=$_GET[year]\" $selected>" date ("F"mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
                }
                
    ?>
              </select>
              <select name="year" id="year" onChange="MM_jumpMenu('parent',this,0)">
              <?
              
    for ($i 2000$i <= 2010$i++) {
                  IF(
    $i == $_GET['year']){
                    
    $selected "selected";
                } ELSE {
                    
    $selected "";
                }
                  echo 
    "<option value=\"index.php?month=$_GET[month]&amp;year=$i\" $selected>$i</option>\n";
              }
              
    ?>
              </select>
            </div></td>
          <td><div align="left"><a href="<? echo "index.php?month=$next_month&amp;year=$next_year"?>">&gt;&gt;</a></div></td>
        </tr>
      </table>
      <br>
    </div>
    <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
      <tr>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="1">
            <tr class="topdays"> 
              <td><div align="center">Sunday</div></td>
              <td><div align="center">Monday</div></td>
              <td><div align="center">Tuesday</div></td>
              <td><div align="center">Wednesday</div></td>
              <td><div align="center">Thursday</div></td>
              <td><div align="center">Friday</div></td>
              <td><div align="center">Saturday</div></td>
            </tr>
            <tr valign="top" bgcolor="#FFFFFF"> 
            <?
            
    for ($i 1$i <= $first_day_of_month-1$i++) {
                
    $days_so_far $days_so_far 1;
                
    $count_boxes $count_boxes 1;
                echo 
    "<td width=\"100\" height=\"100\" class=\"beforedayboxes\"></td>\n";
            }
            for (
    $i 1$i <= $days_in_month$i++) {
                   
    $days_so_far $days_so_far 1;
                    
    $count_boxes $count_boxes 1;
                IF(
    $_GET['month'] == $todays_month+1){
                    IF(
    $i == $todays_date){
                        
    $class "highlighteddayboxes";
                    } ELSE {
                        
    $class "dayboxes";
                    }
                } ELSE {
                    IF(
    $i == 1){
                        
    $class "highlighteddayboxes";
                    } ELSE {
                        
    $class "dayboxes";
                    }
                }
                echo 
    "<td width=\"100\" height=\"100\" class=\"$class\">\n";
                
    $link_month $_GET['month'] - 1;
                echo 
    "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:MM_openBrWindow('event_add.php?day=$i&amp;month=$link_month&amp;year=$_GET[year]','','width=500,height=300');\">$i</a>&nbsp;</span></div>\n";
                IF(isset(
    $events[$i])){
                    echo 
    "<div align=\"left\"><span class=\"eventinbox\">\n";
                    while (list(
    $key$value) = each ($events[$i])) {
                        echo 
    "&nbsp;<a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">" $event_info[$value]['1'] . " " $event_info[$value]['0']  . "</a>\n<br>\n";
                    }
                    echo 
    "</span></div>\n";
                }
                echo 
    "</td>\n";
                IF((
    $count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
                    
    $count_boxes 0;
                    echo 
    "</TR><TR valign=\"top\">\n";
                }
            }
            
    $extra_boxes $count_boxes;
            for (
    $i 1$i <= $extra_boxes$i++) {
                echo 
    "<td width=\"100\" height=\"100\" class=\"afterdayboxes\"></td>\n";
            }
            
    $time_end getmicrotime();
            
    $time round($time_end $time_start3);
            
    ?>
            </tr>
          </table></td>
      </tr>
    </table>
    <p align="center"><span class="footer">&copy; 2008 
        <a href="http://www.kubelabs.com/php_calendar.php">Kubelabs.com</a><br>
        Script Execution Time: <? echo $time?></span><br><br>
        <a href="http://validator.w3.org/check/referer"><img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a> 
    <a href="http://jigsaw.w3.org/css-validator/check/referer"><img border="0" style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a></p>
    </body>
    </html>

    And here is the event_add.php page:
    PHP Code:
    <?
    require_once("includes/config.php");

    session_start();

    $db_connection mysql_connect ($DBHost$DBUser$DBPass) OR die (mysql_error());  
    $db_select mysql_select_db ($DBName) or die (mysql_error());

    if(
    $use_auth)
    {
        if(!isset(
    $_SESSION['admin_id']))
        {
            if ((!isset(
    $_POST['USER'])) AND (!isset($_POST['PASS']))) {
            
    ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
            <head>
            <title>PHPCalendar - Add Event</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <link href="images/cal.css" rel="stylesheet" type="text/css">
            </head>
            
            <body>
            <br><br>
            <form name="form1" method="post" action="event_add.php">
              <table border="0" align="center" cellpadding="0" cellspacing="0">
                <tr> 
                  <td>Username:</td>
                </tr>
                <tr> 
                  <td><input name="USER" type="text" id="USER"></td>
                </tr>
                <tr> 
                  <td height="15">Password:</td>
                </tr>
                <tr> 
                  <td><input name="PASS" type="password" id="PASS"></td>
                </tr>
                <tr> 
                  <td height="50"><div align="center">
                      <input type="submit" name="Submit" value="           login           ">
                    </div></td>
                </tr>
              </table>
            <input type="hidden" name="day" id="day" value="<? echo $_GET['day']; ?>">
            <input type="hidden" name="month" id="month" value="<? echo $_GET['month']; ?>">
            <input type="hidden" name="year" id="year" value="<? echo $_GET['year']; ?>">
            <input type="hidden" name="id" id="id" value="<? echo $_GET['id']; ?>">
            </form>
            </body>
            </html>
            <?
                
    exit;
            } 
            ELSE
            {
                
    $query "SELECT admin_id FROM ".$TBL_PR."admins WHERE admin_username='".addslashes($_POST['USER'])."' AND admin_password='".addslashes(md5($_POST['PASS']))."' LIMIT 1";
                
    $query_result mysql_query ($query);
                while (
    $info mysql_fetch_array($query_result))
                {
                    
    $admin_id $info['admin_id'];
                }
            
                IF(isset(
    $admin_id))
                {
                    
    $_SESSION['admin_id'] = $admin_id;
                }
                ELSE
                {
                    
    header("Location: event_add.php?day=".$_POST['day']."&month=".$_POST['month']."&year=".$_POST['year']."&id=" $_POST['id']);
                    exit;
                }
            }
        }
    }

    IF(isset(
    $_POST['submit']))
    {
        
    $db_table $TBL_PR "events";
        
        
    $_POST['description'] = substr($_POST['description'],0,500);
        
    $_POST['title'] = substr($_POST['title'],0,30);

        
    mysql_query("INSERT INTO $db_table ( `event_id` , `event_day` , `event_month` , `event_year` , `event_time` , `event_title` , `event_desc` ) VALUES ('', '".addslashes($_POST['day'])."', '".addslashes($_POST['month'])."', '".addslashes($_POST['year'])."', '".addslashes($_POST['hour'].":".$_POST['minute'])."', '".addslashes($_POST['title'])."', '".addslashes($_POST['description'])."')");
        
    $_POST['month'] = $_POST['month'] + 1;
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Easy Calendar - Add Event</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language='javascript' type="text/javascript">
    <!--
     function redirect_to(where, closewin)
     {
         opener.location= 'index.php?' + where;
         
         if (closewin == 1)
         {
             self.close();
         }
     }
      //-->
     </script>
    </head>
    <body onLoad="javascript:redirect_to('month=<? echo $_POST['month'].'&year='.$_POST['year']; ?>',1);">
    </body>
    </html>
    <?
    }
    ELSE 
    {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Calendar - Add Event</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="images/cal.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <form name="form1" method="post" action="">
      <table width="480" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Date</span><br> 
            <span class="addeventextrainfo">(MM/DD/YY)</span></td>
          <td height="40" valign="top"> <select name="month" id="month">
              <option value="1" <? IF($_GET['month'] == "1"){ echo "selected"; } ?>>01</option>
              <option value="2" <? IF($_GET['month'] == "2"){ echo "selected"; } ?>>02</option>
              <option value="3" <? IF($_GET['month'] == "3"){ echo "selected"; } ?>>03</option>
              <option value="4" <? IF($_GET['month'] == "4"){ echo "selected"; } ?>>04</option>
              <option value="5" <? IF($_GET['month'] == "5"){ echo "selected"; } ?>>05</option>
              <option value="6" <? IF($_GET['month'] == "6"){ echo "selected"; } ?>>06</option>
              <option value="7" <? IF($_GET['month'] == "7"){ echo "selected"; } ?>>07</option>
              <option value="8" <? IF($_GET['month'] == "8"){ echo "selected"; } ?>>08</option>
              <option value="9" <? IF($_GET['month'] == "9"){ echo "selected"; } ?>>09</option>
              <option value="10" <? IF($_GET['month'] == "10"){ echo "selected"; } ?>>10</option>
              <option value="11" <? IF($_GET['month'] == "11"){ echo "selected"; } ?>>11</option>
              <option value="12" <? IF($_GET['month'] == "12"){ echo "selected"; } ?>>12</option>
            </select> <select name="day" id="day">
              <option value="1" <? IF($_GET['day'] == "1"){ echo "selected"; } ?>>01</option>
              <option value="2" <? IF($_GET['day'] == "2"){ echo "selected"; } ?>>02</option>
              <option value="3" <? IF($_GET['day'] == "3"){ echo "selected"; } ?>>03</option>
              <option value="4" <? IF($_GET['day'] == "4"){ echo "selected"; } ?>>04</option>
              <option value="5" <? IF($_GET['day'] == "5"){ echo "selected"; } ?>>05</option>
              <option value="6" <? IF($_GET['day'] == "6"){ echo "selected"; } ?>>06</option>
              <option value="7" <? IF($_GET['day'] == "7"){ echo "selected"; } ?>>07</option>
              <option value="8" <? IF($_GET['day'] == "8"){ echo "selected"; } ?>>08</option>
              <option value="9" <? IF($_GET['day'] == "9"){ echo "selected"; } ?>>09</option>
              <option value="10" <? IF($_GET['day'] == "10"){ echo "selected"; } ?>>10</option>
              <option value="11" <? IF($_GET['day'] == "11"){ echo "selected"; } ?>>11</option>
              <option value="12" <? IF($_GET['day'] == "12"){ echo "selected"; } ?>>12</option>
              <option value="13" <? IF($_GET['day'] == "13"){ echo "selected"; } ?>>13</option>
              <option value="14" <? IF($_GET['day'] == "14"){ echo "selected"; } ?>>14</option>
              <option value="15" <? IF($_GET['day'] == "15"){ echo "selected"; } ?>>15</option>
              <option value="16" <? IF($_GET['day'] == "16"){ echo "selected"; } ?>>16</option>
              <option value="17" <? IF($_GET['day'] == "17"){ echo "selected"; } ?>>17</option>
              <option value="18" <? IF($_GET['day'] == "18"){ echo "selected"; } ?>>18</option>
              <option value="19" <? IF($_GET['day'] == "19"){ echo "selected"; } ?>>19</option>
              <option value="20" <? IF($_GET['day'] == "20"){ echo "selected"; } ?>>20</option>
              <option value="21" <? IF($_GET['day'] == "21"){ echo "selected"; } ?>>21</option>
              <option value="22" <? IF($_GET['day'] == "22"){ echo "selected"; } ?>>22</option>
              <option value="23" <? IF($_GET['day'] == "23"){ echo "selected"; } ?>>23</option>
              <option value="24" <? IF($_GET['day'] == "24"){ echo "selected"; } ?>>24</option>
              <option value="25" <? IF($_GET['day'] == "25"){ echo "selected"; } ?>>25</option>
              <option value="26" <? IF($_GET['day'] == "26"){ echo "selected"; } ?>>26</option>
              <option value="27" <? IF($_GET['day'] == "27"){ echo "selected"; } ?>>27</option>
              <option value="28" <? IF($_GET['day'] == "28"){ echo "selected"; } ?>>28</option>
              <option value="29" <? IF($_GET['day'] == "29"){ echo "selected"; } ?>>29</option>
              <option value="30" <? IF($_GET['day'] == "30"){ echo "selected"; } ?>>30</option>
              <option value="31" <? IF($_GET['day'] == "31"){ echo "selected"; } ?>>31</option>
            </select> <select name="year" id="year">
              <option value="2008" <? IF($_GET['year'] == "2008"){ echo "selected"; } ?>>2008</option>
              <option value="2009" <? IF($_GET['year'] == "2009"){ echo "selected"; } ?>>2009</option>
              <option value="2010" <? IF($_GET['year'] == "2010"){ echo "selected"; } ?>>2010</option>
            </select> </td>
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Time</span><br> 
            <span class="addeventextrainfo">(24hr Format)</span></td>
          <td height="40" valign="top"> <input name="hour" type="text" id="hour" value="20" size="2" maxlength="2">
            : 
            <input name="minute" type="text" id="minute" value="00" size="2" maxlength="2"> 
          </td>
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Title</span></td>
          <td height="40" valign="top"> <input name="title" type="text" id="title" size="20"> 
          </td>
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Description</span></td>
          <td height="40" valign="top"> <textarea name="description" cols="18" rows="5" id="description"></textarea> 
          </td>
        </tr>
        <tr> 
          <td width="200">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td><input name="submit" type="submit" id="submit" value="Add Event"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    <? 

    ?>

    Thanks in advance to anyone who can help!

    Todd
    Todd Temple > T2 Design

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Add a <select> box to the form so your user can choose AM or PM.

    In the page that processes the form, at the top, do ...
    PHP Code:
    if ($_POST['ampm'] == 'PM') {
      
    $_POST['hour'] = $_POST['hour'] + 12;

    ...to get it back in 24 hour format so you don't have to change any other code.

    (assuming you named the <select> ampm)

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, speaking of calendars... wouldn't it be great to let user set-up a regular recurring schedule !!

    http://www.sitepoint.com/forums/showthread.php?t=662420

    I need advice please.

  4. #4
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Add a <select> box to the form so your user can choose AM or PM.

    In the page that processes the form, at the top, do ...
    PHP Code:
    if ($_POST['ampm'] == 'PM') {
      
    $_POST['hour'] = $_POST['hour'] + 12;

    ...to get it back in 24 hour format so you don't have to change any other code.

    (assuming you named the <select> ampm)
    I apologize, but I am very new to PHP and I do not know exactly where to add the PHP code you have provided. I think I would be adding the code into the event_add.php page since it has the form to add new events, correct? I am just unsure as to where in the top of that file. The very top seems to be asking if the user has already logged in or not. Can you give me a line number of where you would add it?

    Thanks so much for your time!
    Todd Temple > T2 Design

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Todd Temple View Post
    I apologize, but I am very new to PHP and I do not know exactly where to add the PHP code you have provided. I think I would be adding the code into the event_add.php page since it has the form to add new events, correct? I am just unsure as to where in the top of that file. The very top seems to be asking if the user has already logged in or not. Can you give me a line number of where you would add it?

    Thanks so much for your time!
    "Add a <select> box to the form so your user can choose AM or PM."

    below is your code for form. your forms sends data entered to event_add.php. add select box to your form, and his code event_add. hope that helps.

    <body>

    <br><br>

    <form name="form1" method="post" action="event_add.php">

    <table border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>

    <td>Username/td>

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOPS, should have read more carefully - SORRY.
    how about just doing this:

    <option value="07" <? IF($_GET['hour'] == "7"){ echo "selected"; } ?>>7 AM</option>
    <option value="08" <? IF($_GET['hour'] == "8"){ echo "selected"; } ?>>8 AM</option>
    <option value="09" <? IF($_GET['hour'] == "9"){ echo "selected"; } ?>>9 AM</option>
    <option value="10" <? IF($_GET['hour'] == "10"){ echo "selected"; } ?>>10 AM</option>
    <option value="11" <? IF($_GET['hour'] == "11"){ echo "selected"; } ?>>11 AM</option>
    <option value="12" <? IF($_GET['hour'] == "12"){ echo "selected"; } ?>>12 PM</option>
    <option value="13" <? IF($_GET['hour'] == "13"){ echo "selected"; } ?>>1 PM</option>
    <option value="14" <? IF($_GET['hour'] == "14"){ echo "selected"; } ?>>2 PM</option>
    <option value="15" <? IF($_GET['hour'] == "15"){ echo "selected"; } ?>>3 PM</option>
    <option value="16" <? IF($_GET['hour'] == "16"){ echo "selected"; } ?>>4 PM</option>
    <option value="17" <? IF($_GET['hour'] == "17"){ echo "selected"; } ?>>5 PM</option>

    Quote Originally Posted by m300zx View Post
    "Add a <select> box to the form so your user can choose AM or PM."

    below is your code for form. your forms sends data entered to event_add.php. add select box to your form, and his code event_add. hope that helps.

    <body>

    <br><br>

    <form name="form1" method="post" action="event_add.php">

    <table border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>

    <td>Username/td>

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's even better since you don't have to change the processing code at all, or worry about someone typing something weird into the box

  8. #8
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, so I have added the select for the hour minute and a new one for the am/pm options. Below is my edited code. But the question still remains... I think I am adding the GET statement that you suggested to the event_add.php page but I do not see where (or what line of code) to add this stuff:

    (if ($_POST['ampm'] == 'PM') {
    $_POST['hour'] = $_POST['hour'] + 12;
    }

    Also, I am not sure if I should be adding the code above since it seems that a new approach has been suggested. I tested the code below and when I choose 6 from the hour selection, 30 from the minute selection and chose pm, the time displayed on the calendar was 7:02am. Any help?


    PHP Code:
    <?
    require_once("includes/config.php");

    session_start();

    $db_connection mysql_connect ($DBHost$DBUser$DBPass) OR die (mysql_error());  
    $db_select mysql_select_db ($DBName) or die (mysql_error());

    if(
    $use_auth)
    {
        if(!isset(
    $_SESSION['admin_id']))
        {
            if ((!isset(
    $_POST['USER'])) AND (!isset($_POST['PASS']))) {
            
    ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
            <head>
            <title>Main Street Baptist Church - Add Event</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <link href="../c/cal.css" rel="stylesheet" type="text/css">
            </head>
            <body>
            <br><br>
            <form name="form1" method="post" action="event_add.php">
              <table border="0" align="center" cellpadding="0" cellspacing="0">
                <tr> 
                  <td>Username:</td>
                </tr>
                <tr> 
                  <td><input name="USER" type="text" id="USER"></td>
                </tr>
                <tr> 
                  <td height="15">Password:</td>
                </tr>
                <tr> 
                  <td><input name="PASS" type="password" id="PASS"></td>
                </tr>
                <tr> 
                  <td height="50"><div align="center">
                      <input type="submit" name="Submit" value="login">
                    </div></td>
                </tr>
              </table>
            <input type="hidden" name="day" id="day" value="<? echo $_GET['day']; ?>">
            <input type="hidden" name="month" id="month" value="<? echo $_GET['month']; ?>">
            <input type="hidden" name="year" id="year" value="<? echo $_GET['year']; ?>">
            <input type="hidden" name="id" id="id" value="<? echo $_GET['id']; ?>">
            </form>
            </body>
            </html>
            <?
                
    exit;
            } 
            ELSE
            {
                
    $query "SELECT admin_id FROM ".$TBL_PR."admins WHERE admin_username='".addslashes($_POST['USER'])."' AND admin_password='".addslashes(md5($_POST['PASS']))."' LIMIT 1";
                
    $query_result mysql_query ($query);
                while (
    $info mysql_fetch_array($query_result))
                {
                    
    $admin_id $info['admin_id'];
                }
            
                IF(isset(
    $admin_id))
                {
                    
    $_SESSION['admin_id'] = $admin_id;
                }
                ELSE
                {
                    
    header("Location: event_add.php?day=".$_POST['day']."&month=".$_POST['month']."&year=".$_POST['year']."&id=" $_POST['id']);
                    exit;
                }
            }
        }
    }

    IF(isset(
    $_POST['submit']))
    {
        
    $db_table $TBL_PR "events";
        
        
    $_POST['description'] = substr($_POST['description'],0,500);
        
    $_POST['title'] = substr($_POST['title'],0,30);

        
    mysql_query("INSERT INTO $db_table ( `event_id` , `event_day` , `event_month` , `event_year` , `event_time` , `event_title` , `event_desc` ) VALUES ('', '".addslashes($_POST['day'])."', '".addslashes($_POST['month'])."', '".addslashes($_POST['year'])."', '".addslashes($_POST['hour'].":".$_POST['minute'].$_POST['ampm'])."', '".addslashes($_POST['title'])."', '".addslashes($_POST['description'])."')");
        
    $_POST['month'] = $_POST['month'] + 1;
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Add Event - Main Street Baptist Church</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language='javascript' type="text/javascript">
    <!--
     function redirect_to(where, closewin)
     {
         opener.location= 'index.php?' + where;
         
         if (closewin == 1)
         {
             self.close();
         }
     }
      //-->
     </script>
    </head>
    <body onLoad="javascript:redirect_to('month=<? echo $_POST['month'].'&year='.$_POST['year']; ?>',1);">
    </body>
    </html>
    <?
    }
    ELSE 
    {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Add Event</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../c/cal.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <form name="form1" method="post" action="">
      <table width="480" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Date</span><br> 
            <span class="addeventextrainfo">(MM/DD/YY)</span></td>
          <td height="40" valign="top"> <select name="month" id="month">
              <option value="1" <? IF($_GET['month'] == "1"){ echo "selected"; } ?>>01</option>
              <option value="2" <? IF($_GET['month'] == "2"){ echo "selected"; } ?>>02</option>
              <option value="3" <? IF($_GET['month'] == "3"){ echo "selected"; } ?>>03</option>
              <option value="4" <? IF($_GET['month'] == "4"){ echo "selected"; } ?>>04</option>
              <option value="5" <? IF($_GET['month'] == "5"){ echo "selected"; } ?>>05</option>
              <option value="6" <? IF($_GET['month'] == "6"){ echo "selected"; } ?>>06</option>
              <option value="7" <? IF($_GET['month'] == "7"){ echo "selected"; } ?>>07</option>
              <option value="8" <? IF($_GET['month'] == "8"){ echo "selected"; } ?>>08</option>
              <option value="9" <? IF($_GET['month'] == "9"){ echo "selected"; } ?>>09</option>
              <option value="10" <? IF($_GET['month'] == "10"){ echo "selected"; } ?>>10</option>
              <option value="11" <? IF($_GET['month'] == "11"){ echo "selected"; } ?>>11</option>
              <option value="12" <? IF($_GET['month'] == "12"){ echo "selected"; } ?>>12</option>
            </select> <select name="day" id="day">
              <option value="1" <? IF($_GET['day'] == "1"){ echo "selected"; } ?>>01</option>
              <option value="2" <? IF($_GET['day'] == "2"){ echo "selected"; } ?>>02</option>
              <option value="3" <? IF($_GET['day'] == "3"){ echo "selected"; } ?>>03</option>
              <option value="4" <? IF($_GET['day'] == "4"){ echo "selected"; } ?>>04</option>
              <option value="5" <? IF($_GET['day'] == "5"){ echo "selected"; } ?>>05</option>
              <option value="6" <? IF($_GET['day'] == "6"){ echo "selected"; } ?>>06</option>
              <option value="7" <? IF($_GET['day'] == "7"){ echo "selected"; } ?>>07</option>
              <option value="8" <? IF($_GET['day'] == "8"){ echo "selected"; } ?>>08</option>
              <option value="9" <? IF($_GET['day'] == "9"){ echo "selected"; } ?>>09</option>
              <option value="10" <? IF($_GET['day'] == "10"){ echo "selected"; } ?>>10</option>
              <option value="11" <? IF($_GET['day'] == "11"){ echo "selected"; } ?>>11</option>
              <option value="12" <? IF($_GET['day'] == "12"){ echo "selected"; } ?>>12</option>
              <option value="13" <? IF($_GET['day'] == "13"){ echo "selected"; } ?>>13</option>
              <option value="14" <? IF($_GET['day'] == "14"){ echo "selected"; } ?>>14</option>
              <option value="15" <? IF($_GET['day'] == "15"){ echo "selected"; } ?>>15</option>
              <option value="16" <? IF($_GET['day'] == "16"){ echo "selected"; } ?>>16</option>
              <option value="17" <? IF($_GET['day'] == "17"){ echo "selected"; } ?>>17</option>
              <option value="18" <? IF($_GET['day'] == "18"){ echo "selected"; } ?>>18</option>
              <option value="19" <? IF($_GET['day'] == "19"){ echo "selected"; } ?>>19</option>
              <option value="20" <? IF($_GET['day'] == "20"){ echo "selected"; } ?>>20</option>
              <option value="21" <? IF($_GET['day'] == "21"){ echo "selected"; } ?>>21</option>
              <option value="22" <? IF($_GET['day'] == "22"){ echo "selected"; } ?>>22</option>
              <option value="23" <? IF($_GET['day'] == "23"){ echo "selected"; } ?>>23</option>
              <option value="24" <? IF($_GET['day'] == "24"){ echo "selected"; } ?>>24</option>
              <option value="25" <? IF($_GET['day'] == "25"){ echo "selected"; } ?>>25</option>
              <option value="26" <? IF($_GET['day'] == "26"){ echo "selected"; } ?>>26</option>
              <option value="27" <? IF($_GET['day'] == "27"){ echo "selected"; } ?>>27</option>
              <option value="28" <? IF($_GET['day'] == "28"){ echo "selected"; } ?>>28</option>
              <option value="29" <? IF($_GET['day'] == "29"){ echo "selected"; } ?>>29</option>
              <option value="30" <? IF($_GET['day'] == "30"){ echo "selected"; } ?>>30</option>
              <option value="31" <? IF($_GET['day'] == "31"){ echo "selected"; } ?>>31</option>
            </select> <select name="year" id="year">
              <option value="2009" <? IF($_GET['year'] == "2009"){ echo "selected"; } ?>>2009</option>
              <option value="2010" <? IF($_GET['year'] == "2010"){ echo "selected"; } ?>>2010</option>
              <option value="2011" <? IF($_GET['year'] == "2011"){ echo "selected"; } ?>>2011</option>
            </select> </td>
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Time</span><br> 
            </td>
          <td>
          <select name="hour" id="hour">
            <option value="01" <? IF($_GET['hour'] == "1"){ echo "selected"; } ?>>1</option>
            <option value="02" <? IF($_GET['hour'] == "2"){ echo "selected"; } ?>>2</option>
            <option value="03" <? IF($_GET['hour'] == "3"){ echo "selected"; } ?>>3</option>
            <option value="04" <? IF($_GET['hour'] == "4"){ echo "selected"; } ?>>4</option>
            <option value="05" <? IF($_GET['hour'] == "5"){ echo "selected"; } ?>>5</option>
            <option value="06" <? IF($_GET['hour'] == "6"){ echo "selected"; } ?>>6</option>
            <option value="07" <? IF($_GET['hour'] == "7"){ echo "selected"; } ?>>7</option>
            <option value="08" <? IF($_GET['hour'] == "8"){ echo "selected"; } ?>>8</option>
            <option value="09" <? IF($_GET['hour'] == "9"){ echo "selected"; } ?>>9</option>
            <option value="10" <? IF($_GET['hour'] == "10"){ echo "selected"; } ?>>10</option>
            <option value="11" <? IF($_GET['hour'] == "11"){ echo "selected"; } ?>>11</option>
            <option value="12" <? IF($_GET['hour'] == "12"){ echo "selected"; } ?>>12</option>
            </select>
            :
            <select name="hour" id="hour">
            <option value="01" <? IF($_GET['minute'] == "00"){ echo "selected"; } ?>>00</option>
            <option value="02" <? IF($_GET['minute'] == "05"){ echo "selected"; } ?>>05</option>
            <option value="03" <? IF($_GET['minute'] == "10"){ echo "selected"; } ?>>10</option>
            <option value="04" <? IF($_GET['minute'] == "15"){ echo "selected"; } ?>>15</option>
            <option value="05" <? IF($_GET['minute'] == "20"){ echo "selected"; } ?>>20</option>
            <option value="06" <? IF($_GET['minute'] == "25"){ echo "selected"; } ?>>25</option>
            <option value="07" <? IF($_GET['minute'] == "30"){ echo "selected"; } ?>>30</option>
            <option value="08" <? IF($_GET['minute'] == "35"){ echo "selected"; } ?>>35</option>
            <option value="09" <? IF($_GET['minute'] == "40"){ echo "selected"; } ?>>40</option>
            <option value="10" <? IF($_GET['minute'] == "45"){ echo "selected"; } ?>>45</option>
            <option value="11" <? IF($_GET['minute'] == "50"){ echo "selected"; } ?>>50</option>
            <option value="12" <? IF($_GET['minute'] == "55"){ echo "selected"; } ?>>55</option>
            </select>
            <select name="ampm" id="ampm">
            <option value="01" <? IF($_GET['ampm'] == "01"){ echo "selected"; } ?>>am</option>
            <option value="02" <? IF($_GET['ampm'] == "02"){ echo "selected"; } ?>>pm</option>
            </select>
            </td>
          <!--<td height="40" valign="top"> <input name="hour" type="text" id="hour" value="20" size="2" maxlength="2">
            : 
            <input name="minute" type="text" id="minute" value="00" size="2" maxlength="2"> 
          </td>-->
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Title</span></td>
          <td height="40" valign="top"> <input name="title" type="text" id="title" size="20"> 
          </td>
        </tr>
        <tr> 
          <td width="200" height="40" valign="top"><span class="addevent">Event Description</span></td>
          <td height="40" valign="top"> <textarea name="description" cols="18" rows="5" id="description"></textarea> 
          </td>
        </tr>
        <tr> 
          <td width="200">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td><input name="submit" type="submit" id="submit" value="Add Event"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    <? 

    ?>
    Todd Temple > T2 Design

  9. #9
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You don't need the AM/PM selection or code if you do what m300zx suggested in putting all 24 hours (in 12 hour format) in a select box to choose from. And you named your minutes box hour.

    If you're just gonna store the am/pm in the database as part of a string, rather than using a real TIME-type column, then this really doesn't matter...

  10. #10
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so after correcting the error and changing the minutes select to the correct name the minutes problem is solved, but now all entries are showing as "am" even if I choose "pm". Can you tell how I can fix this part? Again, sorry for the constant questions about something that probably seems extremely easy to you guys...

    Todd
    Todd Temple > T2 Design

  11. #11
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Todd Temple View Post
    all entries are showing as "am" even if I choose "pm".

    Todd
    where, or what, shows AM?

  12. #12
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    where, or what, shows AM?
    you have only the first 12 hours. you want all 24.

    <option value="00" <? IF($_GET['hour'] == "0"){ echo "selected"; } ?>>12 AM</option>
    <option value="01" <? IF($_GET['hour'] == "1"){ echo "selected"; } ?>>1 AM</option>
    <option value="02" <? IF($_GET['hour'] == "2"){ echo "selected"; } ?>>2 AM</option>
    <option value="03" <? IF($_GET['hour'] == "3"){ echo "selected"; } ?>>3 AM</option>
    <option value="04" <? IF($_GET['hour'] == "4"){ echo "selected"; } ?>>4 AM</option>
    <option value="05" <? IF($_GET['hour'] == "5"){ echo "selected"; } ?>>5 AM</option>
    <option value="06" <? IF($_GET['hour'] == "6"){ echo "selected"; } ?>>6 AM</option>
    <option value="07" <? IF($_GET['hour'] == "7"){ echo "selected"; } ?>>7 AM</option>
    <option value="08" <? IF($_GET['hour'] == "8"){ echo "selected"; } ?>>8 AM</option>
    <option value="09" <? IF($_GET['hour'] == "9"){ echo "selected"; } ?>>9 AM</option>
    <option value="10" <? IF($_GET['hour'] == "10"){ echo "selected"; } ?>>10 AM</option>
    <option value="11" <? IF($_GET['hour'] == "11"){ echo "selected"; } ?>>11 AM</option>
    <option value="12" <? IF($_GET['hour'] == "12"){ echo "selected"; } ?>>12 PM</option>
    <option value="13" <? IF($_GET['hour'] == "13"){ echo "selected"; } ?>>1 PM</option>
    <option value="14" <? IF($_GET['hour'] == "14"){ echo "selected"; } ?>>2 PM</option>
    <option value="15" <? IF($_GET['hour'] == "15"){ echo "selected"; } ?>>3 PM</option>
    <option value="16" <? IF($_GET['hour'] == "16"){ echo "selected"; } ?>>4 PM</option>
    <option value="17" <? IF($_GET['hour'] == "17"){ echo "selected"; } ?>>5 PM</option>
    <option value="18" <? IF($_GET['hour'] == "18"){ echo "selected"; } ?>>6 PM</option>
    <option value="19" <? IF($_GET['hour'] == "19"){ echo "selected"; } ?>>7 PM</option>
    <option value="20" <? IF($_GET['hour'] == "20"){ echo "selected"; } ?>>8 PM</option>
    <option value="21" <? IF($_GET['hour'] == "21"){ echo "selected"; } ?>>9 PM</option>
    <option value="22" <? IF($_GET['hour'] == "22"){ echo "selected"; } ?>>10 PM</option>
    <option value="23" <? IF($_GET['hour'] == "23"){ echo "selected"; } ?>>11 PM</option>

  13. #13
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ditch the am/pm select box. now you don't need it.

  14. #14
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand ditching the am/pm and adding those into the hour field, but that doesn't seem like it would work well if we have minutes listed too.

    For example, if an event starts at 5:30 pm, we would choose "5AM" and then "30" from the minutes pulldown. The problem would be that the event time would display as "5AM:30".

    So with your solution, would I be adding a ton of new select options like this?

    <option value="08:00" <? IF($_GET['hour'] == "8:00"){ echo "selected"; } ?>>8:00 AM</option>
    <option value="08:05" <? IF($_GET['hour'] == "8:05"){ echo "selected"; } ?>>8:05 AM</option>
    <option value="08:10" <? IF($_GET['hour'] == "8:10"){ echo "selected"; } ?>>8:10 AM</option>
    <option value="08:15" <? IF($_GET['hour'] == "8:15"){ echo "selected"; } ?>>8:15 AM</option>
    <option value="08:20" <? IF($_GET['hour'] == "8:20"){ echo "selected"; } ?>>8:20 AM</option>
    <option value="08:25" <? IF($_GET['hour'] == "8:25"){ echo "selected"; } ?>>8:25 AM</option>
    <option value="08:30" <? IF($_GET['hour'] == "8:30"){ echo "selected"; } ?>>8:30 AM</option>
    <option value="08:35" <? IF($_GET['hour'] == "8:35"){ echo "selected"; } ?>>8:35 AM</option>
    <option value="08:40" <? IF($_GET['hour'] == "8:40"){ echo "selected"; } ?>>8:40 AM</option>
    <option value="08:45" <? IF($_GET['hour'] == "8:45"){ echo "selected"; } ?>>8:45 AM</option>
    <option value="08:50" <? IF($_GET['hour'] == "8:50"){ echo "selected"; } ?>>8:50 AM</option>
    <option value="08:55" <? IF($_GET['hour'] == "8:55"){ echo "selected"; } ?>>8:55 AM</option>
    <option value="09:00" <? IF($_GET['hour'] == "9:00"){ echo "selected"; } ?>>9:00 AM</option>
    <option value="09:05" <? IF($_GET['hour'] == "9:05"){ echo "selected"; } ?>>9:05 AM</option>

    etc. etc.

    That would seem like a ton of select options and a huge dropdown list menu.
    Todd Temple > T2 Design

  15. #15
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done a poor job explaining things. Let's go back to the original code:
    it works fine but is 24 hour format. you want am/pm. so all we have to - the ONLY THING WE NEED TO CHANGE - is the way the form presents HOUR of day to user. here is the code you want:

    <option value="00" <? IF($_GET['hour'] == "0"){ echo "selected"; } ?>>12 AM</option>
    <option value="01" <? IF($_GET['hour'] == "1"){ echo "selected"; } ?>>1 AM</option>
    <option value="02" <? IF($_GET['hour'] == "2"){ echo "selected"; } ?>>2 AM</option>
    <option value="03" <? IF($_GET['hour'] == "3"){ echo "selected"; } ?>>3 AM</option>
    <option value="04" <? IF($_GET['hour'] == "4"){ echo "selected"; } ?>>4 AM</option>
    <option value="05" <? IF($_GET['hour'] == "5"){ echo "selected"; } ?>>5 AM</option>
    <option value="06" <? IF($_GET['hour'] == "6"){ echo "selected"; } ?>>6 AM</option>
    <option value="07" <? IF($_GET['hour'] == "7"){ echo "selected"; } ?>>7 AM</option>
    <option value="08" <? IF($_GET['hour'] == "8"){ echo "selected"; } ?>>8 AM</option>
    <option value="09" <? IF($_GET['hour'] == "9"){ echo "selected"; } ?>>9 AM</option>
    <option value="10" <? IF($_GET['hour'] == "10"){ echo "selected"; } ?>>10 AM</option>
    <option value="11" <? IF($_GET['hour'] == "11"){ echo "selected"; } ?>>11 AM</option>
    <option value="12" <? IF($_GET['hour'] == "12"){ echo "selected"; } ?>>12 PM</option>
    <option value="13" <? IF($_GET['hour'] == "13"){ echo "selected"; } ?>>1 PM</option>
    <option value="14" <? IF($_GET['hour'] == "14"){ echo "selected"; } ?>>2 PM</option>
    <option value="15" <? IF($_GET['hour'] == "15"){ echo "selected"; } ?>>3 PM</option>
    <option value="16" <? IF($_GET['hour'] == "16"){ echo "selected"; } ?>>4 PM</option>
    <option value="17" <? IF($_GET['hour'] == "17"){ echo "selected"; } ?>>5 PM</option>
    <option value="18" <? IF($_GET['hour'] == "18"){ echo "selected"; } ?>>6 PM</option>
    <option value="19" <? IF($_GET['hour'] == "19"){ echo "selected"; } ?>>7 PM</option>
    <option value="20" <? IF($_GET['hour'] == "20"){ echo "selected"; } ?>>8 PM</option>
    <option value="21" <? IF($_GET['hour'] == "21"){ echo "selected"; } ?>>9 PM</option>
    <option value="22" <? IF($_GET['hour'] == "22"){ echo "selected"; } ?>>10 PM</option>
    <option value="23" <? IF($_GET['hour'] == "23"){ echo "selected"; } ?>>11 PM</option>
    </select>

    leave minutes alone - as they were. what's important to understand here is that we have only changed the way the input form presents hours of day to user. we have NOT changed the way time is stored in the DB, and we have NOT changed the way the time is displayed later on. those are a different matter. hope all this makes sense. GOOD LUCK!

  16. #16
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Progress! Thanks, that seems to partially work. The hours select has been added and part of the script is working, but it seems to have shed light on a new problem.

    As the original link to the script shows, there is an index.php page that shows the calendar and displays the events that have been already entered.

    Then there is an event_add.php page that allows an admin to enter a new event. This is the page which has the form on it and it uses itself to process the input. This is the page that I have added the new hour select code to.

    Then there is an event.php page that displays a single event once one is clicked on from the index.php page.

    Let me describe an example entry. I click on a date in the index.php page and enter 8PM from the hour and enter "00" into the minutes text field. The new event should read 8:00PM.

    The event.php page that shows a single event does show the event time to be 8:00 PM, however, the index.php page (that shows the entire month of events) lists the same event as "20:00".

    Can you look at the code I have for the index.php page and tell me where it is using the 24 hour mode?

    INDEX.PHP CODE-
    PHP Code:
    <?
    require_once("includes/config.php");

    if(!isset(
    $installed))
    {
        
    header("Location: install.php");
        exit;
    }
    else
    {
        if(
    file_exists('install.php'))
        {
            
    header("Location: install.php");
            exit;
        }
    }

    $db_connection mysql_connect ($DBHost$DBUser$DBPass) OR die (mysql_error());  
    $db_select mysql_select_db ($DBName) or die (mysql_error());
    $db_table $TBL_PR "events";

    function 
    getmicrotime(){ 
        list(
    $usec$sec) = explode(" ",microtime()); 
        return ((float)
    $usec + (float)$sec); 


    $time_start getmicrotime();

    IF(!isset(
    $_GET['year'])){
        
    $_GET['year'] = date("Y");
    }
    IF(!isset(
    $_GET['month'])){
        
    $_GET['month'] = date("n")+1;
    }

    $month addslashes($_GET['month'] - 1);
    $year addslashes($_GET['year']);

    $query "SELECT event_id,event_title,event_day,event_time FROM $db_table WHERE event_month='$month' AND event_year='$year' ORDER BY event_time";
    $query_result mysql_query ($query);
    while (
    $info mysql_fetch_array($query_result))
    {
        
    $day $info['event_day'];
        
    $event_id $info['event_id'];
        
    $events[$day][] = $info['event_id'];
        
    $event_info[$event_id]['0'] = substr($info['event_title'], 08);;
        
    $event_info[$event_id]['1'] = $info['event_time'];
    }

    $todays_date date("j");
    $todays_month date("n");

    $days_in_month date ("t"mktime(0,0,0,$_GET['month'],0,$_GET['year']));
    $first_day_of_month date ("w"mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));
    $first_day_of_month $first_day_of_month 1;
    $count_boxes 0;
    $days_so_far 0;

    IF(
    $_GET['month'] == 13){
        
    $next_month 2;
        
    $next_year $_GET['year'] + 1;
    } ELSE {
        
    $next_month $_GET['month'] + 1;
        
    $next_year $_GET['year'];
    }

    IF(
    $_GET['month'] == 2){
        
    $prev_month 13;
        
    $prev_year $_GET['year'] - 1;
    } ELSE {
        
    $prev_month $_GET['month'] - 1;
        
    $prev_year $_GET['year'];
    }



    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Calendar of Events</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="images/cal.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div align="center"><span class="currentdate"><? echo date ("F Y"mktime(0,0,0,$_GET['month']-1,1,$_GET['year'])); ?></span><br>
      <br>
    </div>
    <div align="center"><br>
      <table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td><div align="right"><a href="<? echo "index.php?month=$prev_month&amp;year=$prev_year"?>">&lt;&lt;</a></div></td>
          <td width="200"><div align="center">
              <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
                <?
                
    for ($i 1$i <= 12$i++) {
                    
    $link $i+1;
                    IF(
    $_GET['month'] == $link){
                        
    $selected "selected";
                    } ELSE {
                        
    $selected "";
                    }
                    echo 
    "<option value=\"index.php?month=$link&amp;year=$_GET[year]\" $selected>" date ("F"mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
                }
                
    ?>
              </select>
              <select name="year" id="year" onChange="MM_jumpMenu('parent',this,0)">
              <?
              
    for ($i 2000$i <= 2010$i++) {
                  IF(
    $i == $_GET['year']){
                    
    $selected "selected";
                } ELSE {
                    
    $selected "";
                }
                  echo 
    "<option value=\"index.php?month=$_GET[month]&amp;year=$i\" $selected>$i</option>\n";
              }
              
    ?>
              </select>
            </div></td>
          <td><div align="left"><a href="<? echo "index.php?month=$next_month&amp;year=$next_year"?>">&gt;&gt;</a></div></td>
        </tr>
      </table>
      <br>
    </div>
    <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666">
      <tr>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="1">
            <tr class="topdays"> 
              <td><div align="center">Sunday</div></td>
              <td><div align="center">Monday</div></td>
              <td><div align="center">Tuesday</div></td>
              <td><div align="center">Wednesday</div></td>
              <td><div align="center">Thursday</div></td>
              <td><div align="center">Friday</div></td>
              <td><div align="center">Saturday</div></td>
            </tr>
            <tr valign="top" bgcolor="#f5f5f5"> 
            <?
            
    for ($i 1$i <= $first_day_of_month-1$i++) {
                
    $days_so_far $days_so_far 1;
                
    $count_boxes $count_boxes 1;
                echo 
    "<td width=\"100\" height=\"100\" class=\"beforedayboxes\"></td>\n";
            }
            for (
    $i 1$i <= $days_in_month$i++) {
                   
    $days_so_far $days_so_far 1;
                    
    $count_boxes $count_boxes 1;
                IF(
    $_GET['month'] == $todays_month+1){
                    IF(
    $i == $todays_date){
                        
    $class "highlighteddayboxes";
                    } ELSE {
                        
    $class "dayboxes";
                    }
                } ELSE {
                    IF(
    $i == 1){
                        
    $class "highlighteddayboxes";
                    } ELSE {
                        
    $class "dayboxes";
                    }
                }
                echo 
    "<td width=\"100\" height=\"100\" class=\"$class\">\n";
                
    $link_month $_GET['month'] - 1;
                echo 
    "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:MM_openBrWindow('event_add.php?day=$i&amp;month=$link_month&amp;year=$_GET[year]','','width=500,height=300');\">$i</a>&nbsp;</span></div>\n";
                IF(isset(
    $events[$i])){
                    echo 
    "<div align=\"left\"><span class=\"eventinbox\">\n";
                    while (list(
    $key$value) = each ($events[$i])) {
                        echo 
    "&nbsp;<a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">" $event_info[$value]['1'] . " " $event_info[$value]['0']  . "</a>\n<br>\n";
                    }
                    echo 
    "</span></div>\n";
                }
                echo 
    "</td>\n";
                IF((
    $count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
                    
    $count_boxes 0;
                    echo 
    "</TR><TR valign=\"top\">\n";
                }
            }
            
    $extra_boxes $count_boxes;
            for (
    $i 1$i <= $extra_boxes$i++) {
                echo 
    "<td width=\"100\" height=\"100\" class=\"afterdayboxes\"></td>\n";
            }
            
    $time_end getmicrotime();
            
    $time round($time_end $time_start3);
            
    ?>
            </tr>
          </table></td>
      </tr>
    </table>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    </body>
    </html>
    Todd Temple > T2 Design

  17. #17
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while (list($key, $value) = each ($events[$i])) {

    echo "&nbsp;<a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">" . $event_info[$value]['1'] . " " . $event_info[$value]['0'] . "</a>\n<br>\n";

    }
    this WHILE echos the events onto the calendar. it needs a WHILE because there be more than 1 event per day. $value1 is event description. $value0 is event time.

  18. #18
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    this WHILE echos the events onto the calendar. it needs a WHILE because there be more than 1 event per day. $value1 is event description. $value0 is event time.
    Still not understanding where or what I would change to get the index.php page with the entire calendar to display a 12am/12pm time format instead of the current 24 hour.
    Todd Temple > T2 Design


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •