PHP - Getting Wrong Results With Date('c', Mktime())
I'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly.
I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... Code: [Select] $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance. Similar TutorialsNew user of PHP here! I'm using it to display entries from my MYSQL database. Image below. This is the code snippet that displays information from the 'name', 'author' and 'date' columns of my database. I learned this technique from w3schools. $result = mysql_query("SELECT * FROM levels ORDER BY date DESC"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td align='right'>" . $row['date'] . "</td>"; echo "</tr>"; } I would like to use the date() function to format the date differently. But the date() function requires that I convert my time into a timestamp. I know you have to use the mktime() function for this, but I don't know how. Can someone show me how to pass the contents from $row[date] into the mktime() function? Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I have two arrays of strings, one is read in from a file, the other is collected on a previous page using js and passed with a form through $_POST. The array from the file I label $oldImages and the array from the previous page I label $newImages (each is a list of image URLs). I need to compare the two and add them together so that there are no duplicate entries. I'm using array_diff() on them and the result I'm getting includes one entry that is in both arrays. I've tried different ways of reading the file, none of them seem to make any difference in the results. I've been printing the arrays with print_r() to have a look at the contents of the arrays and I decided to use implode() and explode(), and str_replace() to try to remove any irregularities that might be in the objects somehow which I'm not seeing. I'm not a PHP programmer, BTW. Here is some code. I've also attached a screenshot for you--link at the bottom. Code: [Select] <body> <?php $file = file("image_list.txt") or exit("Unable to open file!"); $oldImages = implode($file); $oldImages = str_replace(" ", "", $oldImages); $oldImages = explode("\n", $oldImages); $newImages = implode($_POST); $newImages = str_replace(" ", "", $newImages); $newImages = explode("\n", $newImages); $newAdditions = array_diff($newImages, $oldImages); print_r($newImages); echo '<br><br>'; print_r($oldImages); echo ' <form method="post" action="#"> New Images<br> <textarea id="displayText" rows="5" cols="105" wrap="off" name="existing"> '; foreach($newImages as $key => $entry) echo $entry; //echo $newImages; echo ' </textarea> <br> Stored Images<br> <textarea id="newText" rows="5" cols="105" wrap="off" name="new"> '; foreach($oldImages as $key => $entry) echo $entry; //echo $oldImages; echo ' </textarea> <input type="submit" class="button" value="Submit"><br> </form> Newly Generated Image List<br> <textarea id="newText" rows="30" cols="105" wrap="off" name="new"> '; foreach($newAdditions as $key => $entry) echo $entry; echo ' </textarea> '; ?> <div class="clear"></div> </body> Here is the code from the previous page which produces the array that is stored in $_POST. What you can't see in this code is the javascript functions toggleEntry() and displayList(). All they do is handle the addition and removal of image URL strings to/from the textarea object, which I do using document.getElementById('text').InnerHTML=$myList, where $myList has strings being added or removed to/from it. Code: [Select] <script type="text/javascript" src="/js/user_selection_list_builder.js"></script> <script type="text/javascript"> function toggleAndDisplay(key) { toggleEntry(key); displayList(); } </script> </head> <body> <form method="post" action="add_images2.php"> Selected Images<br> <textarea id="displayText" rows="10" cols="90" wrap="off" name="comments"> </textarea> <input type="submit" class="button" value="Submit"> </form> <div class="clear"></div> <?php $i = 2; include 'simple_html_dom.php'; if($i===1) $html = file_get_html('lookbook-source.htm'); elseif($i===2) $html = file_get_html('http://lookbook.nu/preference/look-list-gender/girls'); elseif($i===3) $html = file_get_html('http://lookbook.nu/new'); // Match all div tags of the class 'look_photo'. foreach($html->find('div[class=look_photo]') as $key => $entry) { echo " <div class='imgBox'> <a href='javascript:toggleAndDisplay(".$key.")'><img id='".$key."' src='".$entry->last_child()->last_child()->src."'></a> </div> "; } ?> </body> Hi everyone. I'm stuck on the following query. I need to display all the fields listed below on a page, but linked via communications.CommID. I'd appreciate any assistance you can provide. thank you. Code: [Select] <?php $result = mysql_query("SELECT records.NameFirst_1, records.NameLast_1, records.CompanyName, records.CompanyBranch, records.CompanyReferenceNumber, records.CaseOwnerSelect, communications.ConversionType, communications.Contact, communications.ContactFrom, communications.CommID, communications.ContactPosition, communications.ContactTelephone, communications.ContactEmail, communications.ContactFax, communications.CallDate, communications.CallTime, communications.ActionTextField FROM records INNER JOIN communications ON records.IDNumber = '$IDNumber'") or die(mysql_error()); $row = mysql_fetch_array($result); ?> Good Evening, What I am trying to do in here is to display data based on my selected option in the drop down list. I don't have submit button, I just want it to automatically display results based on my selection. Here's my code: <link href="add_client.css" rel="stylesheet" type="text/css"> <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["territory"])) { $query .= " WHERE territory LIKE '%".$_POST["territory"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="trustlist.php" method="post"> <table width="293" border="0"> <tr> <td width="140" align="left" valign="middle"> SEARCH RECORD: </td> <td width="143" align="center" valign="middle"><select name="territory" id="territory" style="width: 143px" width="230"> <option selected="selected" disabled="disabled">Select Territory</option> <option>Territory 01</option> <option>Territory 02</option> <option>Territory 03</option> <option>Territory 04</option> <option>Territory 05</option> <option>Territory 06</option> <option>Territory 07</option> <option>Territory 08</option> <option>Territory 09</option> <option>Territory 10</option> </select></td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="148" align="center" bgcolor="#E0E8F3">Acute Trusts</th> <th width="262" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 AsiaLimited. All rights reserved. </td> </table></td> </tr> </table> Our product is running on LAMP(PHP) architecture. For MySQL operation PDO library has been used. We are in the process of moving the product to a new Linux server. On the new server we are facing MySQL query output related issue. At the end of the post I have listed the server configuration details of both the servers and the sample PHP program with the output. It works fine in server 1 but when the same code moved to Server 2, the output is not correct. Would appreciate any points to solve this problem The following piece of code is tested and output is also given. <?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'ram'; /*** mysql password ***/ $password = 'tellmehow'; try { $dbh = new PDO("mysql:host=$hostname;dbname=inhouse", $username, $password); $sql = "SELECT first_name,last_name,user_id,email FROM users LIMIT 1"; $stmt = $dbh->prepare($sql,array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE)); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_OBJ); $stmt->closeCursor(); /*foreach($result as $key=>$val) { echo $key.' - '.$val.'<br />'; }*/ print_r($result); $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } ?> Output for server 1: stdClass Object ( [first_name] => super [last_name] => admin [user_id]=>1 [email] => ram@greynium.com ) output for server 2: stdClass Object ( [first_name] => super [last_name] => admin [users] => ram@greynium.com ) On server 2 I am not getting the output for field 'user_id' from the table 'users'. For the field 'email' from 'users' table, it is displaying the name of the table itself (users). Not sure what is wrong. The configuration of the servers are given below Server 1 -------- OS Details: Linux 2.6.9-5.ELsmp PHP Details: PHP 5.2.3 (cli) (built: Aug 28 2007 11:48:30) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with Suhosin v0.9.22, Copyright (c) 2007, by SektionEins GmbH PDO details: PDO PDO support => enabled PDO drivers => sqlite2, sqlite, mysql PDO Driver for MySQL, client library version => 5.0.37 PDO Driver for SQLite 3.x => enabled Server 2 --------- OS Details: Linux 2.6.18-8.el5 PHP Details: eAccelerator requires Zend Engine API version 220060519. The Zend Engine API version 220090626 which is installed, is newer. Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator. PHP 5.3.2 (cli) (built: Jul 6 2010 17:57:31) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies PDO Details: PDO PDO support => enabled PDO drivers => mysql, sqlite, sqlite2 PDO Driver for MySQL => enabled PDO Driver for SQLite 3.x => enabled I have a MySQL column which holds the date in DATETIME format. When I pull it and try and format it in php using the DATE function the times are wrong. See code below: <?php print date("d/m/y @ G:H:s A", strtotime($pt->transaction_date)); ?> Anyone know why this is the case ? Hi, when i try to insert to table date value it gives me wrong current date. $joindate = date('m-d-Y'); $sql = mysqli_query($con,"INSERT INTO staff (OracleID,StaffName,Des,joindate,username,password,isadmin) VALUES ('$oracleid','$name','$des','$joindate','$username', '$pass','$isadmin')"); i get this in the main page after making date("d-m-Y",strtotime(date)) 30-11--0001 why is that? Edited April 7, 2020 by ramiwahdanHey All, As of this morning our gallery has started to show the incorrect dates. Please go to: http://www.nightlifeguestlist.com/c...n/74/Carbon.htm you will see the first date is Fri, 29 October 10 this should be Sat, 30 October 10. In the database the date is in putted as 2010-10-30. The dates from Fri, 29 October 10 to Fri, 2 April 10 are all incorrect. These happen to be all BST times. While the dates for GMT are OK. The clocks here in the UK are now GMT and not BST. Has this anything to do with it? The code used is as follows: <? $location = false; if(isset($_GET['l'])){ $location = $_GET['l']; } $venue = false; if(isset($_GET['v'])){ $venue = $_GET['v']; } $event = false; if(isset($_GET['e'])){ $event = $_GET['e']; } $page = 0; if(isset($_GET['p'])){ $page = $_GET['p']; $page--; } $query_events = ""; if(!$location){ $query_events = "SELECT ec_venues.location FROM ec_venues GROUP BY ec_venues.location"; } else if($location && !$venue && !$event){ $query_events = "SELECT ec_venues.venue_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_id, ec_events.event_id,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_date IS NOT NULL AND ec_venues.location='".$location."' ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC LIMIT 0,1"; } else if($venue && !$event){ $query_events = "SELECT UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_name, ec_venues.venue_id, ec_events.event_id, ec_events.event_name,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_venues.venue_id=".$venue." ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC"; } else if($venue && $event){ $query_events = "SELECT ec_venues.venue_name, ec_events.event_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_events.image_folder, ec_venues.images_per_page,ec_venues.location FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_id=".$event." AND ec_venues.venue_id=".$venue.""; } mysql_select_db($database_nightlife2 , $nightlife2 ); // $query_events = "SELECT ec_venues.venue_name, ec_events.event_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_events.image_folder, ec_venues.images_per_page FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ec_events.event_id=".$event." AND ec_venues.venue_id=".$venue.""; //echo $query_events; $events = mysql_query($query_events, $nightlife2 ) or die(mysql_error()); $row_events = mysql_fetch_assoc($events); $totalRows_events = mysql_num_rows($events); ?> <!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=iso-8859-1" /> <title><?=(!$location?"Elite Parties Photos":"Nightlife Guestlist @ ".$location." Club - ".$row_events['venue_name'])?></title> <link href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/style.css" rel="stylesheet" type="text/css" /> <!--[if IE 6]> <link rel="stylesheet" type="text/css" href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/IE-6.css" /> <![endif]--> <!--[if IE]> <link rel="stylesheet" type="text/css" href="http://www.nightlifeguestlist.com/wp-content/themes/NLGL/IE-8.css" /> <![endif]--> <? if($_SERVER['HTTP_HOST']=="elite"){?> <BASE HREF="http://elite/"> <? } else { ?> <BASE HREF="http://www.nightlifeguestlist.com/"> <? } ?> <SCRIPT language="JavaScript" src="/mircoFinestra.js"></script> <script src="/AC_RunActiveContent.js" type="text/javascript"></script> </style> </head> <body> <div class="wrapper"> <div id="head"> <div id="header"> </div> <!-- nav --> <div id="nav"> <div id="nav-area"> <ul> <li class='page_item current_page_item'><a href='http://www.nightlifeguestlist.com' title='Home'>Home</a></li><li class="page_item page-item-3"><a href="http://www.nightlifeguestlist.com/guest-lists" title="Guest Lists">Guest Lists</a></li> <li class="page_item page-item-5"><a href="http://www.nightlifeguestlist.com/photogallery.php" title="Photo Gallery">Photo Gallery</a></li> <li class="page_item page-item-7"><a href="http://www.nightlifeguestlist.com/video-gallery" title="Video Gallery">Video Gallery</a></li> <li class="page_item page-item-9"><a href="http://www.nightlifeguestlist.com/jobs" title="Jobs">Jobs</a></li> <li class="page_item page-item-11"><a href="http://www.nightlifeguestlist.com/membership" title="Mailing List">Mailing List</a></li> <li class="page_item page-item-16"><a href="http://www.nightlifeguestlist.com/tables" title="Tables">Tables</a></li> <li class="page_item page-item-13"><a href="http://www.nightlifeguestlist.com/event-management" title="Event Management">Event Management</a></li> <li class="page_item page-item-538"><a href="http://www.nightlifeguestlist.com/blog" title="Blog">Gossip Blog</a></li> </ul> </div> </div> <!-- end nav --> <div class="clear"></div> </div> <!--/head --> <div class="narrowcolumn"> <div class="entry"> <div id="content-area"> <!-- 1 --> <div id="section"> <? if($venue && !$event){ ?><?php $pCount = 0; $myNum = sprintf("%02d",$venue); echo "<img src='interiors/" . $myNum . "_logo.gif' vspace='2' hspace='2'>\n"; if ($handle = opendir('interiors')) { while (false !== ($file = readdir($handle))) { if (substr($file,0,6) == $myNum . "_pic") { echo '<img src="interiors/' . $file . '" vspace="2" hspace="2">'; if($pCount++ % 2 == 1) echo ""; } } closedir($handle); } ?> <? } ?> <? if(!$location){?> <!-- 2 --> <div id="section"> <? do{ $query_latest = "SELECT ec_venues.venue_name, UNIX_TIMESTAMP(ec_events.event_date) AS event_date, ec_venues.venue_id, ec_events.event_id FROM ec_events INNER JOIN ec_venues ON ec_events.venue_id = ec_venues.venue_id WHERE ((ec_events.event_date) IS NOT NULL) AND ec_venues.location='".$row_events['location']."' ORDER BY UNIX_TIMESTAMP(ec_events.event_date) DESC LIMIT 0,1"; $latest = mysql_query($query_latest, $nightlife2 ) or die(mysql_error()); $row_latest = mysql_fetch_assoc($latest); $totalRows_latest = mysql_num_rows($latest); ?> <a href="club_dates/<?=$row_events['location']?>/<?=$row_latest['venue_id']?>/<?=$row_latest['event_id']?>/<?=str_replace(" ","_",$row_latest['venue_name'])?>_page1.htm "><?=$row_events['location']?> - <?php echo date("l jS F",$row_latest['event_date']); ?> @ <?php echo $row_latest['venue_name']; ?></a><br> <? } while ($row_events = mysql_fetch_assoc($events)); mysql_free_result($latest); ?> </div> <!-- 3 --> <div id="section"> <? } else if(!$venue){ ?> </div> <!-- 4 --> <div id="section"> Our most recent event was <strong><a style="color:#000000; font-weight:bold;" href="club_dates/<?=$row_events['location']?>/<?=$row_events['venue_id']?>/<?=$row_events['event_id']?>/<?=str_replace(" ","_",$row_events['venue_name'])?>_page1.htm "><?php echo date("l jS F",$row_events['event_date']); ?> @ <?php echo $row_events['venue_name']; ?></a></strong> <? } else if($venue && !$event){?> </div> <!-- 5 --> <div id="section"> <table width="100%" border="0" align="left" cellpadding="0" cellspacing="10"> <tr> <td colspan="4"><? if($totalRows_events==0){ ?> No photos are avaliable yet for this venue. <? } else { ?> Select a Date for <?php echo $row_events['venue_name']; ?> <? } ?> </td> </tr> <? $count = 0; do { if($count % 3 == 0){ echo '<tr>'; } ?> <td width="713"><a style="color:#000000; font-weight:bold;" href="club_dates/<?=$location?>/<?=$venue?>/<?=$row_events['event_id']?>/<?=str_replace(" ","_",$row_events['venue_name'])?>_page1.htm"><? echo ($row_events['event_date']==""?$row_events['event_name']:date("D, j F y",$row_events['event_date'])); ?></a></td> <?php if($count % 3 == 2){ echo "</tr>"; } $count++; } while ($row_events = mysql_fetch_assoc($events)); echo str_repeat("<td> </td>",4-($count % 4)); ?> </table> </div> <!-- 6 --> <div id="section"> <? } else if($venue && $event){ ?> </div> <!-- 7 --> <div id="section"> <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td><? if ($dir = @opendir("photos/".$row_events['image_folder'])){ while (($file = readdir($dir)) !== false) { if(substr($file,0,4) == "page"){ $dirlist[] = $file; } } sort ($dirlist); reset ($dirlist); closedir($dir); } if ($dir = @opendir("photos/".$row_events['image_folder']."/".$dirlist[$page])){ while (false !== ($file = readdir($dir))) { if(substr($file,-3)=="jpg"){ $imglist[] = $file; } } usort($imglist,"strnatcmp"); reset ($imglist); closedir($dir); } $count = 0; $paging = ""; if($page==0){ $paging .= "<< "; } else $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($page).".htm' style='color:#000000; font-weight:bold;'><<</a> "; foreach($dirlist as $f){ if($page!=$count){ $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($count+1).".htm' style='color:#000000; font-weight:bold;'>".($count+1)."</a> "; } else { $paging .= ($count+1)." "; } $count++; } if($page==count($dirlist)-1){ $paging .= ">> "; } else $paging .= "<a href='/club_dates/".$location."/".$venue."/".$event."/".str_replace(" ","_",$row_events['venue_name'])."_page".($page+2).".htm' style='color:#000000; font-weight:bold;'>>></a>"; ?></td> </tr> <tr> <td><? echo "<table width='720'><tr><td>Nightlife Guestlist @ ".$row_events['venue_name'].($row_events['event_date']!="" ?" - ".date("l jS F Y", $row_events['event_date']) : "")." - ".$location."</td><td align='right'>".$paging."</td></tr></table>\n"; ?></td> </tr> <tr> <td><? for($count=0;$count<count($imglist);$count++){ echo "<a href='javascript:;'><img alt='".$imglist[$count]." @ ".$location." Club ".$row_events['venue_name'].", ".date("jS F Y", $row_events['event_date'])."' border='0' width='90px' height='60px' hspace='5px' vspace='5px' src='"."photos/".$row_events['image_folder']."/".$dirlist[$page]."/thumbs/".$imglist[$count]."' onclick='NewWindow(\"/popup.php?t=".count($imglist)."&n=".$count."&f=".$row_events['image_folder']."&p=".$dirlist[$page]."&title=".urlencode($location." Club ".$row_events['venue_name']." on ".date("jS F Y", $row_events['event_date']))."\",\"name\",\"600\",\"420\",\"no\");return false;'></a>\n"; if($count % 7 == 6){ echo "<br>\n"; } } ?> <? } ?></td> </tr> <tr> <td> </td> </tr> </table> </div> <div id="section"> <? if(!$location){ ?> <? } else { include("getClubLogos.php"); } ?> (Sorry for the amount of code!) I use the same code for another site on another server and it works fine. I guess I need to alter the code somehow? The gallery works ok just the dates show are wrong. Any ideas on how to fix this? The server settings/time seems are OK. The line which prints the date is:<? echo ($row_events['event_date']==""?$row_events['event_name']:date ("D, j F y", $row_events['event_date'])) ; ?> When I echo the date echo date('c'); I receive 2010-10-29T23:00:00+00:00 for Fri, 29 October 10. Thanks I am retrieving data using AJAX. I would like to sort them from newest to oldest date. Currently they show from oldest to newest. How do I do that? <div id="output"></div> <script> $(document).ready(function(){ $.ajax ({ type: 'GET', url: "https://3rdpartywebsite.com/api/getcustomers", dataType: 'json', success: function(data) { $.each(data, function(i, v) { var customerId = v.customerId; var firstName = v.firstName; var lastName = v.lastName; var createdDateTime = v.createdDateTime; $('#output').append('<ul class="output-ul">' + '<li>' + customerId + '</li>' + '<li>' + firstName + '</li>' + '<li>' + lastName + '</li>' + '<li>' + createdDateTime + '</li>' + '</ul>'); }); } }); }); </script>
I am trying create a webpage that will automatically display new agendas as I add them to the server. I do this right now but I have to put the agendas in the agendas and the board folders. I want to simplify this by only putting the agendas in the board folder. My code kinda works but the results aren't sorted correctly. My code scans the current directory for the list of current boards. The arrary_diff removes the boards that are no longer active. It then appends the current year to the folder information. Next I glob all of the Agendas in the various directories and then I sort the resulting glob. Finally I print the results which are out of date order. I tried sort(basename($agendas)) but that is not valid syntax for sort. Then I was thinking of a 2 dimension array, the first element is the filename, the second element is the fullpath. Then I sort on the first element but I haven't figured out how to get that to work. So I went back to my first code and I am asking what did I do wrong? Am I on the right track to do what I want? The directory structure is like this: Array ( [0] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/01-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [1] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/02-24-2021_Board_of_Zoning_Appeals_Agenda.pdf [2] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/03-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [3] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf [4] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/01-24-2021_EDC_Agenda.pdf [5] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/02-21-2021_EDC_Agenda.pdf [6] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/03-21-2021_EDC_Agenda.pdf [7] => ./meeting-minutes-agendas/Park_Board/2021/01-21-2021_Park_Board_Agenda.pdf [8] => ./meeting-minutes-agendas/Park_Board/2021/02-18-2021_Park_Board_Agenda.pdf [9] => ./meeting-minutes-agendas/Park_Board/2021/03-18-2021_Park_Board_Agenda.pdf [10] => ./meeting-minutes-agendas/Park_Board/2021/03-27-2021_Park_Board_Agenda.pdf [11] => ./meeting-minutes-agendas/Park_Board/2021/04-22-2021_Park_Board_Agenda.pdf [12] => ./meeting-minutes-agendas/Plan_Commission/2021/01-07-2021_Plan_Commission_Agenda.pdf [13] => ./meeting-minutes-agendas/Plan_Commission/2021/01-21-2021_Plan_Commission_Agenda.pdf [14] => ./meeting-minutes-agendas/Plan_Commission/2021/02-04-2021_Plan_Commission_Agenda.pdf [15] => ./meeting-minutes-agendas/Plan_Commission/2021/02-18-2021_Plan_Commission_Agenda.pdf [16] => ./meeting-minutes-agendas/Plan_Commission/2021/03-04-2021_Plan_Commission_Agenda.pdf [17] => ./meeting-minutes-agendas/Plan_Commission/2021/03-18-2021_Plan_Commission_Agenda.pdf [18] => ./meeting-minutes-agendas/Plan_Commission/2021/04-08-2021_Plan_Commission_Agenda.pdf [19] => ./meeting-minutes-agendas/Plan_Commission/2021/04-22-2021_Plan_Commission_Agenda.pdf [20] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/01-17-2021_RDC_Agenda.pdf [21] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/02-14-2021_RDC_Agenda.pdf [22] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/03-14-2021_RDC_Agenda.pdf [23] => ./meeting-minutes-agendas/Safety_Board/2021/01-08-2021_Safety_Board_Agenda.pdf [24] => ./meeting-minutes-agendas/Safety_Board/2021/02-16-2021_Safety_Board_Agenda.pdf [25] => ./meeting-minutes-agendas/Safety_Board/2021/03-16-2021_Safety_Board_Agenda.pdf [26] => ./meeting-minutes-agendas/Safety_Board/2021/04-22-2021_Safety_Board_Agenda.pdf [27] => ./meeting-minutes-agendas/Sanitary_District/2021/01-19-2021_Sanitary_District_Agenda.pdf [28] => ./meeting-minutes-agendas/Sanitary_District/2021/02-16-2021_Sanitary_District_Agenda.pdf [29] => ./meeting-minutes-agendas/Sanitary_District/2021/03-16-2021_Sanitary_District_Agenda.pdf [30] => ./meeting-minutes-agendas/Sanitary_District/2021/03-23-2021_Sanitary_District_Agenda.pdf [31] => ./meeting-minutes-agendas/Sanitary_District/2021/03-31-2021_Sanitary_District_Agenda.pdf [32] => ./meeting-minutes-agendas/Sanitary_District/2021/04-20-2021_Sanitary_District_Agenda.pdf [33] => ./meeting-minutes-agendas/Town_Council/2021/01-13-2021_Town_Council_Agenda.pdf [34] => ./meeting-minutes-agendas/Town_Council/2021/01-27-2021_Town_Council_Agenda.pdf [35] => ./meeting-minutes-agendas/Town_Council/2021/02-02-2021_Town_Council_Agenda.pdf [36] => ./meeting-minutes-agendas/Town_Council/2021/02-24-2021_Town_Council_Agenda.pdf [37] => ./meeting-minutes-agendas/Town_Council/2021/03-03-2021_Town_Council_Agenda.pdf [38] => ./meeting-minutes-agendas/Town_Council/2021/03-24-2021_Town_Council_Agenda.pdf [39] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Special_Meeting_Agenda.pdf [40] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Study_Session_Agenda.pdf [41] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-07-2021_Waterwork_Board_Agenda.pdf [42] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-19-2021_Waterworks_Board_Agenda.pdf [43] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-28-2021_Waterworks_Board_Agenda.pdf [44] => ./meeting-minutes-agendas/Waterworks_Board/2021/02-16-2021_Waterworks_Board_Agenda.pdf [45] => ./meeting-minutes-agendas/Waterworks_Board/2021/03-16-2021_Waterworks_Board_Agenda.pdf [46] => ./meeting-minutes-agendas/Waterworks_Board/2021/04-20-2021_Waterworks_Board_Agenda.pdf ) What I get is
04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf when it should be:
04-20-2021_Sanitary_District_Agenda.pdf <?php $files = array_diff(scandir('./meeting-minutes-agendas'), array('..', '.', 'Default.php', 'Agendas', 'Police_Commission', 'Utility_Board')); sort($files); foreach($files as &$file) { $file = $file . "/" . date("Y"); } unset($file); $agendas = array(); foreach($files as $file) { $temp = glob('./meeting-minutes-agendas/'. $file . "/*Agenda.pdf"); $agendas = array_merge($agendas, $temp); } unset($files); unset($temp); sort($file); foreach($agendas as $file) { $filedate = str_replace('-', '/',substr(basename($file),0,10)); if (strtotime($filedate) >= strtotime(date('m/d/Y'))) { echo "<a href='"; echo $file; echo "'>"; $file = str_replace('.php', '', $file); echo basename($file); echo "</a><br>\n"; } } unset($file); ?>
I think it is unusual but i dont know to fix it. when my computer clock shows 16: 13 hours , date() reuturns 10:43:16 . My systems time zone is +5.30 GMT. how does date() subtracts 5.30 hrs from the system time? First, I would like to say when i tried to recover my account from this website, I took me 10 attempts to get the captcha right and then finally it said it sent me an email to my gmail account. I checked spam folder and everything there was no such email from this site. Then I decided to create a new account, well, it took me another 10 attempts to get the captcha right and finally when it was submitted, the page was loading for around 3 minutes before it signed me in.
My question is about the php date() function. It accepts a format to display a time. In the following example I use F for full representation of month, d for 2-digit day of month with leading zeros, Y for full year, g for 12-hour format without leading 0s, s for seconds and A for meridiem. It uses the correct format, but it gives me the wrong time. My local time is 4:43 and it prints out 4:12:
<?php echo "<p>order processed on " . date("F d, Y g:sA") . "</p>"; ?> Why is it 30 minutes behind? My friend a I have to different numbers when we echo mktime(0,0,0,5,12,1990). How is this possible? I thought that only, we you leave some parameters blank, the local this is used, else, it's standardized. thanks in advance how do I use strtotime() instead of mktime()? $matchTimea = mktime($mHour, $mMinute, 0, $mMonth, $mDay, $mYear); if($matchTimea-time() < $cutoffTimea*60) { I'm an extreme newbie and have this current error on my site. The error states: Warning: mktime() expects parameter 4 to be long, string given in featured_product.php on line 75 <?php for ($i = 0; $i < $num_rows; $i++) { $id = mysql_result($result,$i,"id"); $title = mysql_result($result,$i,"title"); $featured = mysql_result($result,$i,"featured"); $feature_date = mysql_result($result,$i,"feature_date"); $feature_date_arr = explode("-",$feature_date); $feat_date = mktime(0,0,0,$feature_date_arr[0],$feature_date_arr[1],2000+$feature_date_arr[2]); if ( ($feat_date+($featured*24*60*60))<time() ) { $db2->query("UPDATE product_catalog SET featured = 0 WHERE id='$id'"); $featured = 0; } else { $featured = 1; $db2->query("UPDATE product_catalog SET featured = 1 WHERE id='$id'"); } ?> Any ideas on how to correct this? Thanks! right now i have my date system to say "X amount of seconds ago, X hours ago, X days ago, X years ago, How could i turn mktime() (1290874161) into a mm/dd/yyyy format? so it would say like, "Nov 27, 2010 at Hour:Minute" (whatever the hour/minute is) Or am I just going crazy? OK, I've been running a query that uses the snippet below to get the previous month. It's : Code: [Select] $sql = "SELECT COUNT(`id`) as `counted` FROM `click_tracking` WHERE `date` LIKE '". date('Y-m', mktime(0, 0, 0, (date('m')-1), date('d'), date('Y'))) ."-%'"; Here's a snippet for people to try: Code: [Select] date_default_timezone_set('America/Toronto'); echo date('Y-m', mktime(0, 0, 0, (date('m')-1), date('d'), date('Y'))); //prints 2012-03 (March, which is incorrect; should be February- 2012-02) That should have printed 2012-02, but instead, it prints 2012-03. If I modify the mktime() to (date('m')+1): Code: [Select] date_default_timezone_set('America/Toronto'); echo date('Y-m', mktime(0, 0, 0, (date('m')+1), date('d'), date('Y'))); //prints 2012-05 (May, which is incorrect; should be April - 2012-04) It prints 2012-05 which is incorrect for the given timezone. Should be 2012-04 I'm thinking it's a leap year bug and will work itself out tomorrow (per my timezone, anyways). So, when I use the mktime() function, it seems to be thinking we're in April already. A standard date('Y-m') prints the correct YYYY-MM (2012-03) though. Am I tripping out? Hi, I'm getting this error: Warning: mktime() expects parameter 5 to be long, string given in /home/user/public_html/include/functions.php on line 58 The code is: if($Date_Format == 1) #For dd-mm-yyyy { $Date_Output = date("d-m-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 2) #For dd/mm/yyyy { $Date_Output = date("d/m/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 3) #For mm-dd-yyyy { $Date_Output = date("m-d-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 4) #For mm/dd/yyyy { $Date_Output = date("m/d/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 5) #For Mon Day YYYY { $Date_Output = date("M D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 6) #For Month Day YYYY { $Date_Output = date("F D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 7) #For Date"nd" Month YYYY { $Date_Output = date("d\\t\h F Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 8) #For Month Day YYYY { $Date_Output = date("F d Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 9) #For Month Day YYYY { $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); // Line 58 } return $Date_Output; } else { return NULL; Line 58 says $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); I really appreciate any help on this. I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners |