PHP - Working With Dates
I need to do some reporting and I need some help. The reporting periods are as follows:
08/28-09/03 09/04-09/10 09/11-09/17 09/18-09/24 09/25-10/01 So, they are Sunday through Saturday throughout each month. Say the date is Sept. 7.... How can I find out the date of the Sunday before last. How can I know what month I am reporting for? I am querying the database each Wed. for sales data from the previous month. I want to take the totals from my query and store them in a separate table. The problem is, I don't know how to find out what month the previous week falls into. And I don't know how to find the date of the Sunday before last. Thanks, Jake Similar TutorialsHi There, I am trying to use PHP to create a calendar that only show's working days - which are monday to friday. Is there any way that PHP can return a list of the next 5 working day's dates? For example, if today is Thursday 15th Sept - could it return the numbers 15,16,19,20 and 21? Thanks Matt Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. Thanks Hi guys, I am trying to create a program which manages campaigns. each campaign has a start date and and end date. a user has to enter data releated to the campaign everyday example start date: 10-1-2011 end date: 17-1-2011 now all this information is stored in 2 tables 1st table is "campaigns" this stores the campaign name, start date and end date and 2nd table is "campaign_data" this table stored the data for each campaign and also date of when that data was entered my question is, if the user did not enter data on 11-1-2011 how will I know this, keeping in mind the month diffrence which can accur if the length of the campign was 2 month long? table: campaigns fields: id | campaign_name | start_date | end_date table: campaign_data fields: id | campaign_id | date | page Thank you Hey, I have just recently coded a forum and my topics are ordered by date. This means if there is a topic at 4pm and then there is another topic made at 4:01pm the topic which was posted at 4:01pm will be listed at the top. I know how to add timezones but there is bit of a problem, if person from the UK posts a topic and his/hers timezone is set to: date_default_timezone_set('Europe/London');() this means the time at which the topic was posted will be 20:36pm (Just a randome time example). However if someone posted a topic from america/los_angeles one hour before the one above his/her time will be 11:36 am. Even though this topic was posted one hour before the UK post. The UK topic will override it because it is 8:36pm. In fact, all UK topics will show up at the top and all the america/los_angeles topics will show bellow. How do I slove this problem? I just don't get it even tough I looked online. Please help, thanks. Hi, So I only want my users to be able to perform certain tasks each 12 hours. This is the code I use: Code: [Select] function canVote($ip, $vote_id, $updateTimer = true){ $time = date("Y-m-d H:i:s"); $this->CI->db->where('vote_id', $vote_id); $this->CI->db->where('user_ip', $ip); $this->CI->db->from('votes_voters'); $count = $this->CI->db->count_all_results(); /*$count = $this->CI->db ->where('vote_id =', $vote_id) ->where('user_ip =', $ip) ->from('votes_voters') -count_all_results();*/ $row = $this->CI->db ->where('vote_id =', $vote_id) ->where('user_ip =', $ip) ->get('votes_voters') ->row(); if($count == 0){ $data = array( 'vote_id' => $vote_id, 'user_ip' => $ip, 'last_vote' => $time ); $this->CI->db->insert('votes_voters', $data); return true; } else{ $last_vote = $row->last_vote; if($last_vote + strtotime("12 hours") < $time){ return false; } else{ if($updateTimer = true){ $data = array( 'last_vote' => $time, ); $this->CI->db->where('vote_id', $vote_id); $this->CI->db->where('user_ip', $ip); $this->CI->db->update('votes_voters', $data); } return true; } } } Apparently the failing bit is this: Code: [Select] if($last_vote + strtotime("12 hours") < $time){ return false; } I believe you can guess what I'm trying to do here, if variable 1 + 12 hours is smaller than variable 2, then return false. Any help is much appreciated. i want to created a case like the following need help with the syntax: Code: [Select] switch (true) { case($fromdate-$todate==17-04-2001-25-04-2011): echo $finalprice = $result; break; } Hey guys, What I'm trying to do is set 2 dates. Today's date and then a date 14 days from now. However, I want it to increase the month if by adding 14 days will bring me to the next month, same with the year. I have this, but it doesn't increment the month or year. $week = mktime(11, 59, 59, date("m"), date("d")+14, date("y")); $date = date("Y-m-d H:i:s", $week); Hi again! I'm trying to use this code that i found somewhere in the net to display all the dates between 2 dates. It is exactly what i need but.. I understand the code and its structure (i think) but it gives me an error (maximum execution time of blah blah) which i think is because it makes an infinite loop(not sure.. ) Code: [Select] function GetDays($sStartDate, $sEndDate) { $sStartDate = gmdate("Y-m-d", strtotime($sStartDate)); $sEndDate = gmdate("Y-m-d", strtotime($sEndDate)); $aDays[] = $sStartDate; $sCurrentDate = $sStartDate; while($sCurrentDate < $sEndDate){ $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate))); $aDays[] = $sCurrentDate; } return $aDays; } Appreciate the help and suggestions! Gonna browse the forums for answers for the meantime... Hello. I wanted to make a table where the dates are listed going forward at least one year. So, at least 365 records, but each date should be unique and should start from today until one year from now. I tried to make a date column and make it a primary key.
However, an error comes up when I try to insert more than one record. This is for a calendar that I'm building so I need the dates listed one year in advance and it would be great if new dates could be added without my having to manually go in there and insert new records to stick to my 1 year in advance rule.
For that aspect I might have to create a php script where the date records are added every time a user logs in, to make sure they are up to date, but anyways what I don't understand is why I can't make a table with 1 year of date records in advance, where each row has a unique date starting from today.
There are two things I want done. 1. Grab the current date in TIMESTAMP form and increase by a certain number of days as assigned by $days() 2. Similar to the previous one, it will grab an already specified TIMESTAMP, and work from there All it echoes is 86400, which I assume is the number of seconds? Code: [Select] <?php $days = 1; echo strtotime("+$days days", strtotime($date)); ?> Hi I'm trying to get this to work. I have known date in MySQL database entered as 2019-08-01 and I need to calculate from that date to current time. What I have is this code $date_ts = strtotime($row['date_ts']); //Timestamp $date_str = date("M-d-Y", $date_ts); //String in format MMM-DD-YYYY $TotalTime = floor((time() - $date_ts)/(60*60*24)) . ' days';//Total in days but my result showing as ==> 18367 days Could someone please help me get this to work so it shows the right number of days. thank you
When just generating HTML, where should dates be formatted? What about when generating JSON (I've found that date formatting is not so straight forward using JavaScript)? Are there factors which may make one approach better than the other (i.e. querying one record versus a list of records)? How important is consistency of an approach? Any other factors I should consider? Please provide rational for your decision. Thank you
At the database?
DATE_FORMAT(my_date, "%m/%d/%Y %r") AS my_dateIn the controller? $date = new DateTime($my_date); $my_date=$date->format('m/d/Y');In a twig or smarty template? {{ mydate|date("m/d/Y g:i A") }}At the client using handlebars and the Moment library? UI.registerHelper("formatDate", function(datetime, format) { if (moment) { f = DateFormats[format]; return moment(datetime).format(f); } else { return datetime; } }); ... {{formatDate MyISOString "short"}} Hi, I have a created comment system, now what i am after is when the comment is posted the time is posted in hidden format. All is going fine but what i don't know, what should the time be posted as example date(H:m:s) or... the result i want is time in minutes first e.g. commented 2 mins ago and increasing to hours after that days. Could some one kindly guide me in the right directions. I have looked and looked around on google, but I can't seem to enter the right keywords for this. I have an events page and I need the events to only display between the date ranges...........startdate and enddate. here is the entire code for the page, Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } // Set error message as blank upon arrival to page $errorMsg = ""; // First we check to see if the form has been submitted if (isset($_POST['username'])){ $name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $phone = ereg_replace("[^A-Z a-z0-9]", "", $_POST['phone']); // filter everything but spaces, numbers, and letters $username = ereg_replace("[^A-Z a-z0-9]", "", $_POST['username']); // filter everything but spaces, numbers, and letters $address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters $city = ereg_replace("[^A-Za-z0-9]", "", $_POST['city']); // filter everything but lowercase letters $state = ereg_replace("[^A-Za-z0-9]", "", $_POST['state']); // filter everything but lowercase letters $zip = ereg_replace("[^A-Za-z0-9]", "", $_POST['zip']); // filter everything but lowercase letters $cell = ereg_replace("[^A-Za-z0-9]", "", $_POST['cell']); // filter everything but lowercase letters $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); if((!$email)){ $errorMsg = "You did not submit the following required information!<br /><br />"; if(!$email){ $errorMsg .= "--- Email Address"; } } else { $sql = mysql_query("INSERT INTO events (name, phone, username, address, city, state, zip, cell, email) VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email") or die (mysql_error()); $to = "$email"; // Change this to your site admin email $from = "events@final.net46.net"; $subject = "Complete your registration"; //Begin HTML Email Message where you need to change the activation URL inside $message = '<html> <body bgcolor="#FFFFFF"> Hi ' . $username . ', <br /><br /> You must complete this step to activate your account with us. <br /><br /> Please click here to activate now >> <a href="http://www.somewebsite.com/activation.php?id=' . $id . '"> ACTIVATE NOW</a> <br /><br /> Your Login Data is as follows: <br /><br /> E-mail Address: ' . $email . ' <br /> Password: ' . $password . ' <br /><br /> Thanks! </body> </html>'; // end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; $to = "$to"; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br /> We just sent an Activation link to: $email<br /><br /> <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br /> Link inside the message. After email activation you can log in."; exit(); // Exit so the form and page does not display, just this success message } // Close else after database duplicate field value checks } // Close else after missing vars check //Close if $_POST ?> <?php // if no id is specified, list the available articles if(!isset($_GET['eventid'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT eventid, event, startdate, enddate FROM Registration ORDER BY eventid"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($eventid, $event, $startdate, $enddate) = $row; $as = "<a href=\"$self?eventid=$eventid\">$startdate - $enddate --- $event</a>\r\n"; } $Events = 'Events'; } else { // get the article info from database $query = "SELECT event, description, startdate, enddate, location, subevent1, subevent2, subevent3, subevent4, subevent5, subevent6, subevent7, subevent8, price1, price2, price3, price4, price5, price6, price7, price8 FROM Registration WHERE eventid=".$_GET['eventid']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $event = $row['event']; $description = $row['description']; $startdate = $row['startdate']; $enddate = $row['enddate']; $location = $row['location']; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Register</title> <style type="text/css"> #apDiv1 { position:absolute; left:33px; top:320px; width:252px; height:48px; z-index:1; } #apDiv2 { position:absolute; left:33px; top:361px; width:254px; height:46px; z-index:2; } #apDiv3 { position:absolute; left:33px; top:525px; width:256px; height:43px; z-index:3; } #apDiv4 { position:absolute; left:33px; top:402px; width:250px; height:48px; z-index:4; } #apDiv5 { position:absolute; left:106px; top:616px; width:263px; height:255px; z-index:5; } #apDiv6 { position:absolute; left:323px; top:200px; width:898px; height:530px; z-index:5; } #apDiv7 { position:absolute; left:33px; top:443px; width:266px; height:42px; z-index:6; } #apDiv8 { position:absolute; left:111px; top:500px; width:125px; height:37px; z-index:7; } #apDiv8 strong { font-size: 24px; } #apDiv9 { position:absolute; left:33px; top:408px; width:267px; height:49px; z-index:8; } #apDiv10 { position:absolute; left:33px; top:449px; width:242px; height:23px; z-index:9; } #apDiv8 a { color: #000; } #apDiv11 { position:absolute; left:101px; top:490px; width:168px; height:42px; z-index:10; font-size: 24px; font-weight: bold; } #apDiv11 a { color: #000; } #apDiv12 { position:absolute; left:33px; top:210px; width:205px; height:107px; z-index:11; } #apDiv12 { text-align: center; } #apDiv13 { position:absolute; left:33px; top:320px; width:248px; height:47px; z-index:12; } #apDiv { position:absolute; left:33px; top:484px; width:225px; height:35px; z-index:11; } #apDiv14 { position:absolute; left:33px; top:566px; width:298px; height:51px; z-index:12; } #apDiv15 { position:absolute; left:101px; top:611px; width:168px; height:42px; z-index:10; font-size: 24px; font-weight: bold; } #apDiv5 a { font-size: 24px; color: #000; font-weight: bold; } #apDiv23 table tr td1 { font-size: 14px; } </style> <script type="text/javascript"> function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> <style type="text/css"> #apDiv6 #form1 table tr th { text-align: center; } #apDiv6 table tr td table tr td { text-align: center; } #apDiv16 { position:absolute; left:330px; top:45px; width:208px; height:100px; z-index:13; } #apDiv6 table tr td #apDiv16 table tr th { font-size: 36px; } #apDiv17 { position:absolute; left:183px; top:342px; width:427px; height:65px; z-index:13; } #apDiv6 table tr td #Accordion1 .AccordionPanel.AccordionPanelOpen .AccordionPanelContent #apDiv17 table tr th { color: #999; } </style> <style type="text/css"> #apDiv19 { position:absolute; left:33px; top:320px; width:271px; height:33px; z-index:13; } #apDiv20 { position:absolute; left:578px; top:368px; width:157px; height:87px; z-index:14; } #apDiv21 { position:absolute; left:8px; top:705px; width:270px; height:683px; z-index:15; } #apDiv22 { position:absolute; left:476px; top:313px; width:596px; height:124px; z-index:16; } #apDiv6 table tr td table tr th { text-align: left; } #apDiv23 { position:absolute; left:326px; top:30px; width:247px; height:85px; z-index:16; text-align: center; font-size: 36px; } #apDiv23 table tr td { text-align: center; font-size: 24px; } #apDiv24 { position:absolute; left:364px; top:202px; width:247px; height:63px; z-index:17; text-align: center; font-size: 20px; } .klgjsa { font-size: 18px; } #apDiv24 { font-size: 16px; } #apDiv24 { font-size: 18px; } #apDiv24 { color: #C90; } #apDiv23 { color: #F00; } #apDiv24 { color: #000; } a:link { color: #C90; } a:visited { color: #C90; } a:hover { color: #000; } </style> </head> <body onload="MM_preloadImages('button/pictures2.png','button/projects1.png','button/news2.png','button/eventmanager2.png','button/membermanager2.png','button/newsmanager2.png','button/myprofile2.png')"> <div id="apDiv6"> <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699"> <tr> <td bgcolor="#FFFFFF"><h1 align="center"><?php echo $Events; ?></h1> <p> </p> <p> </p> <p><strong><?php echo $as; ?></strong> </p> <p> </p> <p> </p> <?php $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; } $q = mysql_query("SELECT * FROM Registration WHERE eventid=".$_GET['eventid'].""); while($row = mysql_fetch_array($sql)){ $event= $row["event"]; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; } ?> <?php // when displaying an article show a link // to see the article list if(isset($_GET['eventid'])) { ?> <div id="jQueryUIAccordion"> <h3> </h3> <div> <p> <div id="apDiv23"><?php echo $event; ?> <br /> </div> <div id="apDiv24"><?php echo $startdate;?> <span class="klgjsa">-</span> <?php echo $enddate; ?></div> <table width="575" border="0" cellspacing="2" cellpadding="2"> <tr> <th width="563" bgcolor="#999999" scope="col">Location</th> </tr> </table> <table width="574" height="16" border="0" cellpadding="2" cellspacing="2"> <tr> <th height="12" scope="col"><?php echo $location; ?></th> </tr> </table> <table width="573" border="0" cellspacing="2" cellpadding="2"> <tr> <th width="561" bgcolor="#999999" scope="col">Description</th> </tr> </table> <table width="576" border="0" cellspacing="2" cellpadding="2"> <tr> <th width="564" height="11" scope="col"><?php echo $title1; ?><br /><?php echo $price1; ?></th> <th width="564" scope="col"><?php echo $subevent1; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title2; ?><br /><?php echo $price2; ?></th> <th scope="col"><?php echo $subevent2; ?> </th> </tr> <tr> <th height="11" scope="col"><?php echo $title3; ?><br /><?php echo $price3; ?></th> <th scope="col"><?php echo $subevent3; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title4; ?><br /><?php echo $price4; ?></th> <th scope="col"><?php echo $subevent4; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title5; ?><br /><?php echo $price5; ?></th> <th scope="col"><?php echo $subevent5; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title6; ?><br /><?php echo $price6; ?></th> <th scope="col"><?php echo $subevent6; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title7; ?><br /><?php echo $price7; ?></th> <th scope="col"><?php echo $subevent7; ?></th> </tr> <tr> <th height="11" scope="col"><?php echo $title8; ?><br /><?php echo $price8; ?></th> <th scope="col"><?php echo $subevent8; ?></th> </tr> </table> <hr /> <table width="200" border="0" cellspacing="2" cellpadding="2"> <tr> <th scope="col">Price:</th> </tr> </table> <table width="200" border="0" cellspacing="2" cellpadding="2"> <tr> <th scope="col">$<?php echo $price; ?></th> </tr> </table> </p> <?php if (isset($_GET['eventid'])) { include('connect1.php'); $sql = mysql_query("SELECT * FROM Registration WHERE eventid='$eventid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $eventid = $row["eventid"]; $event = $row["event"]; $date = $row["date"]; $description = $row["description"]; $location = $row["location"]; } $result = mysqli_query($dbcon, $query) or die('error getting data'); echo "<table>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr><td>"; echo "<a href=\"registration.php?eventid=".$_GET['eventid']."\"><ul>Register Now!</ul></a>"; echo "</td></tr>"; } echo "</table>"; } ?> <div id="apDiv18"></div> <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Back to Events</a></p> <?php } ?></td></tr> </table> </div><div id="apDiv2"><a href="register.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','button/register2.png',1)"><img src="button/register1.png" name="Image3" width="235" height="50" border="0" id="Image3" /></a></div> <div id="apDiv4"><a href="projects.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','button/projects2.png',1)"><img src="button/projects1.png" name="Image4" width="235" height="50" border="0" id="Image4" /></a></div> <div id="apDiv11"><?php if ($accounttype == "Scout") { echo '<a href="../logout.php">Logout</a>';} ?></div> <div id="apDiv12"><?php echo "$accounttype"; ?> <p><?php echo "$name"; ?></p> <p>Troop 78</p> </div> <div id="apDiv5"><?php if ($accounttype == "Admin") { echo "<a href=\"../logout.php\">Logout</a>"; } ?></div> <div id="apDiv7"><a href="news.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','button/news2.png',1)"><img src="button/news1.png" name="Image6" width="235" height="50" border="0" id="Image6" /></a></div> <div id="apDiv"> <?php if ($accounttype == "Admin") { echo "<a href=\"../search1.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image7','','../button/membermanager2.png',1)\"><img src=\"../button/membermanager1.png\" name=\"Image7\" width=\"235\" height=\"50\" border=\"0\" id=\"Image7\" /></a>"; } ?></div> <div id="apDiv3"><?php if ($accounttype == "Admin") { echo "<a href=\"../eventmanager.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image8','','../button/eventmanager2.png',1)\"><img src=\"../button/eventmanager1.png\" name=\"Image8\" width=\"235\" height=\"50\" border=\"0\" id=\"Image8\" /></a>"; } ?> </div> <div id="apDiv14"><?php if ($accounttype == "Admin") { echo "<a href=\"../newsmanager.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image9','','../button/newsmanager2.png',1)\"><img src=\"../button/newsmanager1.png\" name=\"Image9\" width=\"235\" height=\"50\" border=\"0\" id=\"Image9\" /></a>"; } ?> </div> <div id="apDiv19"><a href="myprofile.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','button/myprofile2.png',1)"><img src="button/myprofile1.png" name="Image5" width="235" height="50" border="0" id="Image5" /></a></div> <div id="apDiv21"><img src="button/red.png" width="282" height="687" /></div> <img name="boyscout" src="buttons/boyscout.jpg" width="1180" height="700" border="0" id="boyscout" alt="" /> </body> </html> This is a big big big part of website and so I really need this to be working. Is there also a way I could possibly display this by events in a month instead of by day? If any body could help me, that would be so awesome. Hello Everyone, I seem to be going no place fast... In a PHP file, I should be taking a date from a jquery datpicker, and get it to a format that mysql will read in the yy-mm-dd format with... if(isset($_POST['choice'])) $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); Can't seem to get a single inline(embeded) jquery Datepicker date to post right to the PHP and mysql correctly to return data from the table.. My reading has me to understand it should be right, but it is not. Now the datepicker select does have several POST events to PHP that trigger from the single select... data being requsted in PHP by the day, month, and year as well as PHP to use the date to create a highcharts graph in the PHP file to select data for hours of a day, days of a month, and months of a year. The Table is very simple... date, time, power Here is the PHP for dayPower.php that will just collect the sum data for the selected day in the datepicker... <? if(isset($_POST['choice'])) $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); $con = mysql_connect("localhost","root","mackie1604"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = 'SELECT sum(power) AS power ' .'FROM feed ' .'WHERE date = $choice'; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); echo $row['power']; ?> Here is the javascript that sends the date and how it post the PHP file. Code: [Select] $(document).ready(function () { $('#datepicker').datepicker({onSelect: function(dateText,inst) { var myDate = $(this).datepicker('getDate'); $('#apDiv1').html($.datepicker.formatDate('DD, d', myDate)); $('#apDiv5').html($.datepicker.formatDate('MM', myDate)); $('#apDiv7').html($.datepicker.formatDate('yy', myDate)); $.post('dayPower.php', {choice: inst.val()}, function(data) { $('#apDiv2').html(data).show(); }); $.post('dayGraph.php', {choice: inst.val()}, function(data) { $('#apDiv4').html().show(); }); $.post('monthPower.php', {choice: inst.val()}, function(data) { $('#apDiv6').html(data).show(); }); $.post('monthGraph', {choice: inst.val()}, function(data) { $('#apDiv9').html().show(); }); $.post('yearPower.php', {choice: inst.val()}, function(data) { $('#apDiv8').html(data).show(); }); $.post('yearGraph', {choice: inst.val()}, function(data) { $('#apDiv10').html().show(); }); }}); }); What am I doing wrong Alan so i have a basic html table and down the left column i have monday,tuesday,wednesday.... sunday. In the column 2nd from the left, i want to fill it with the current weeks dates, which is really based on the current date. So if today is Jul 29th Friday, then strtotime("last monday") would give me Jul 26th Monday... my issue is "last monday" wont work if today is monday because that will give me 19th of july... and since I technically dont know what day is today i'm not sure how to cleanly work around this without having to use some if statement... if today is monday do "last monday +7 days" or just do "now" etc... Thanks! Hi All, Bit stuck on something I think should be quite simple. I have a table which includes events that have a state date and end date (startdate, enddate). I've got a search function that pulls out with various criteria etc, however i'm now doing a search by date. For example, an event may start on 1st Jan 2011 and finish on 1st May 2011. If my search for which events are on on the 2nd February; it should pull the above event out, as it lies inbetween those dates. Code: [Select] SELECT * FROM events WHERE ((DAY(events.startdate <= '".date('d',$day)."') AND DAY(events.enddate >= '".date('d',$day)."')) AND MONTH(events.startdate <= '".date('m',$day)."') AND MONTH(events.enddate >= '".date('m',$day)."')) Theres a bunch of other stuff joining tables etc, but you get the idea. For some reason this isn't working? I've got it working by month, but month AND day is eluding me. I also need to add in the year, but that isn't so important at the moment. Any help would be amazing! Thanks E Hi, I'm trying to get the date, using this code <?php include('config.php'); $today = date('Y-m-d 00:00:00'); $nineyesterday = date('Y-m-d H:i:s', mktime(date("H") - (date("H") + 6), date("i") - date("i"), date("s") - date("s"), date("m") , date("d"), date("Y"))); $now = date('Y-m-d H:i:s'); $nineam = date('Y-m-d 9:00:00'); $ninepm = date('Y-m-d 18:00:00'); if ((strtotime($now) >= strtotime($today)) && (strtotime($now) <= strtotime($nineam))) { //count the answers by yes or no $q = "SELECT opt, count(opt) FROM plus_poll_ans WHERE date<='".$nineyesterday."' AND date>='".$nineam."' GROUP BY opt desc "; } elseif ((strtotime($now) >= strtotime($nineam)) && (strtotime($now) <= strtotime($ninepm))) { //count the answers by yes or no $q = "SELECT opt, count(opt) FROM plus_poll_ans WHERE date<'".$nineam."' AND date>='".$ninepm."' GROUP BY opt desc "; } $q = mysql_query($q) or die(mysql_error()); //separate the results while($row = mysql_fetch_array($q)) { $total_opt[] = $row['count(opt)']; } mysql_freeresult($q); $yes = intval($total_opt[0]); $no = intval($total_opt[1]); $total = $yes + $no; echo $total."<br/>"; echo $yes."<br/>"; echo $no."<br/>"; ?> but it didn't work, why isn't it working? Thanks |