<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1043556" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1043556</link>
    <description></description>
    <language>en</language>
          <item>
    <title>I take on board your</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240330</link>
    <description> &lt;p&gt;I take on board your comments and advice, and thanks for taking the time to respond.&lt;/p&gt;
&lt;p&gt;I just felt an additional table and mysql searching wouldn&#039;t be as efficient as small amount of additional PHP (explode that field).&lt;br /&gt;
Especially as any table caching will change (new rows inserted), where as the PHP doesn&#039;t change.&lt;br /&gt;
I also understand the future proofing could be useful in most other scenarios.&lt;/p&gt;
&lt;p&gt;Mysql optimisation is definitely something I need to bury my head in. And performance tweaking of PHP versus mysql etc.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Sun, 12 Apr 2009 13:49:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1240330 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>greg wrote:
But I don&#039;t</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240325</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;But I don&#039;t need to as the events listings doesn&#039;t nor ever will require to do so.&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Are you sure you need a relational database at all?&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;Ok, but I still need:&lt;br /&gt;
&lt;em&gt;An additional table, more ID associations required between tables, an additional table to query, an additional table to insert and maintain&lt;/em&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;There is nothing inherently wrong with this.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;I have a field that has the last date of each event.&lt;br /&gt;
When the DB is inserted with the range of timestamps from the input array, the last one is added the table field &quot;last_date&quot;&lt;/p&gt;
&lt;p&gt;$var = the timestamp from 24 hours ago (which was the point of this thread!)&lt;br /&gt;
&lt;code&gt;WHERE last_date &amp;gt; $var&lt;/code&gt;&lt;br /&gt;
So if the last date is from 24 hours ago and beyond, get data. &lt;/p&gt;
&lt;p&gt;With my approach, that&#039;s all done within one table.&lt;br /&gt;
Table is queried to find where &quot;last_date&quot; is greater than timestamp from 24 hours ago, and if returns true, then all the data I need is right there in that very row.&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;This is a large amount of complexity for a very small optimisation in a single case.  This approach completely discounts the future of the application (requirements will change), and defeats the purpose of using a relational database (better to use an optimised object store).&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;Whereas with your method (for this particular circumstance) the additional requirement of searching another table is a bad thing.&lt;br /&gt;
As then it&#039;s running through an entire table to see where dates are greater than timestamp from 24 hours ago, then it has to get the association Id, go to another table, find the row that matches that ID and fetch all the data from that row.&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;This is not necessarily a large cost; and even if you wanted to optimise for your isolated case, you could still use your technique of caching the last date in the events table.  SQL JOINs are also deeply optimised in most RDMS systems; I suggest you try it and benchmark the results to see if it&#039;s really as bad as you imagine.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;As always best practice for PHP and DB structures is always down to the specific requirements. Also, future proofing for things that wont ever be required is potentially additional tables/fields or PHP that might not ever be used.&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Your aversion to tables is baffling, especially here when one additional table will eschew some ad hoc string-based storage of a list of timestamps that complicates work on the client side and wastes the DBMS.  The robustness and flexibility your application gains by normalising this will probably be worth more in the long-term than the apparent (and unproven) performance loss you expect.&lt;/p&gt;
&lt;p&gt;This is really a basic idea in relational database design.  If you remain unconvinced, I suppose only the pain of having to extend a poorly normalised schema will persuade you otherwise.  I would still recommend reading about database normalisation and then reconsidering your approach.&lt;/p&gt;
&lt;p&gt;Good luck.&lt;/p&gt;
 </description>
     <pubDate>Sun, 12 Apr 2009 00:50:40 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1240325 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Abhishek Reddy wrote:
You</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240322</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Abhishek Reddy&lt;/em&gt; wrote:&lt;/div&gt;You cannot, for instance, perform a conditional SQL query upon timestamp ranges.&lt;/div&gt;But I don&#039;t need to as the events listings doesn&#039;t nor ever will require to do so.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Abhishek Reddy&lt;/em&gt; wrote:&lt;/div&gt;That&#039;s incorrect, you would not need an additional query in PHP.  Use a SQL JOIN in a single query&lt;/div&gt;Ok, but I still need:&lt;br /&gt;
&lt;em&gt;An additional table, more ID associations required between tables, an additional table to query, an additional table to insert and maintain&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Abhishek Reddy&lt;/em&gt; wrote:&lt;/div&gt;Let&#039;s say we want to find every event which has occurred at least once in the last 24 hours.  With your approach, we would have to select every event, parse its timestamps value in PHP, looping again to filter the results.&lt;/div&gt;When I list an event the description, links etc are all wrapped in one area (div) for that one event with the one title. Each date and time for that event are listed under that one event.&lt;br /&gt;
So when I query the events for everything from 24 hours ago, it is simply from the last date the event runs. This is to allow for people to see events not yet taken place.&lt;br /&gt;
Once the event date is beyond 24 hours, it goes into archived page (which simply list all where timestamp is smaller than timestamp from 24 hours).&lt;/p&gt;
&lt;p&gt;I have a field that has the last date of each event.&lt;br /&gt;
When the DB is inserted with the range of timestamps from the input array, the last one is added the table field &quot;last_date&quot;&lt;/p&gt;
&lt;p&gt;$var = the timestamp from 24 hours ago (which was the point of this thread!)&lt;br /&gt;
&lt;code&gt;WHERE last_date &amp;gt; $var&lt;/code&gt;&lt;br /&gt;
So if the last date is from 24 hours ago and beyond, get data. &lt;/p&gt;
&lt;p&gt;With my approach, that&#039;s all done within one table.&lt;br /&gt;
Table is queried to find where &quot;last_date&quot; is greater than timestamp from 24 hours ago, and if returns true, then all the data I need is right there in that very row.&lt;/p&gt;
&lt;p&gt;Whereas with your method (for this particular circumstance) the additional requirement of searching another table is a bad thing.&lt;br /&gt;
As then it&#039;s running through an entire table to see where dates are greater than timestamp from 24 hours ago, then it has to get the association Id, go to another table, find the row that matches that ID and fetch all the data from that row.&lt;/p&gt;
&lt;p&gt;As always best practice for PHP and DB structures is always down to the specific requirements. Also, future proofing for things that wont ever be required is potentially additional tables/fields or PHP that might not ever be used.&lt;/p&gt;
&lt;p&gt;So with my scenario I don&#039;t think adding a new table with associations to other tables and having to scan through TWO tables instead of one is more efficient.&lt;/p&gt;
&lt;p&gt;I do however see your logic and agree that in other scenarios, your method would be useful, and more efficient even with that additional table.&lt;/p&gt;
 </description>
     <pubDate>Sat, 11 Apr 2009 18:04:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1240322 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>greg wrote:
Why would that</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240320</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;Why would that be better?&lt;/p&gt;
&lt;p&gt;Currently I have:&lt;br /&gt;
&lt;em&gt;Data from one field in a table I already query, one field data gets exploded into an array, then a simple loop on the array to echo out all the values.&lt;/em&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;The fact that this thread exists is one symptom of the deep problem with this approach.  You cannot, for instance, perform a conditional SQL query upon timestamp ranges.  Rather defeats the purpose of using a relational database at all.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;&lt;br /&gt;
&lt;em&gt;An additional table, more ID associations required between tables, another query in PHP for the new table with now multiple row queries and therefore an additional bunch of table searches, I would need an additional loop to store each row result in an array and still need to then loop the array to echo out values&lt;/em&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That&#039;s incorrect, you would not need an additional query in PHP.  Use a SQL JOIN in a single query to select related records from the events and occurrences tables together.  The result set will be contained in a single multidimensional array, as it is now, but with additional fields.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;&lt;br /&gt;
I don&#039;t see at all how that would be more efficient.&lt;br /&gt;
Don&#039;t get me wrong, I am still picking up tips so if there&#039;s a reason please tell me.&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Let&#039;s say we want to find every event which has occurred at least once in the last 24 hours.  With your approach, we would have to select every event, parse its timestamps value in PHP, looping again to filter the results.&lt;/p&gt;
&lt;p&gt;The efficiency costs include: spending memory allocated to PHP on copies of unnecessary data; computing string operations and type conversions on every record&#039;s timestamps; wasting time looping over all data again in PHP to select the final result.&lt;/p&gt;
&lt;p&gt;Using a normalised schema, in direct comparison: will only spend memory allocated to the database once on (parts of) unneeded records; will apply conditional checks using optimised algorithms; will yield a result set ready to be consumed without excess processing by PHP.&lt;/p&gt;
 </description>
     <pubDate>Sat, 11 Apr 2009 16:38:36 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1240320 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Why would that be</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240312</link>
    <description> &lt;p&gt;Why would that be better?&lt;/p&gt;
&lt;p&gt;Currently I have:&lt;br /&gt;
&lt;em&gt;Data from one field in a table I already query, one field data gets exploded into an array, then a simple loop on the array to echo out all the values.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Versus&lt;br /&gt;
&lt;em&gt;An additional table, more ID associations required between tables, another query in PHP for the new table with now multiple row queries and therefore an additional bunch of table searches, I would need an additional loop to store each row result in an array and still need to then loop the array to echo out values&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I don&#039;t see at all how that would be more efficient.&lt;br /&gt;
Don&#039;t get me wrong, I am still picking up tips so if there&#039;s a reason please tell me.&lt;/p&gt;
 </description>
     <pubDate>Sat, 11 Apr 2009 13:48:55 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1240312 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>greg wrote:
As the events</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240307</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;greg&lt;/em&gt; wrote:&lt;/div&gt;As the events can occur over multiple days, and therefore potentially 2 months &amp;amp; two years (Dec 28 to Jan 5), I have multiple timestamps for each event. The event has no true limit for days it could span to allow for a set total sql field allowance, so I enter them in one field with a delimiter, then splitting at the delimiter and the largest timestamp for the split is taken as the &quot;latest&quot;.&lt;/p&gt;
&lt;p&gt;Otherwise that may have been useful .&lt;/p&gt;
&lt;p&gt;I don&#039;t like using one field for multiple stuff and then splitting by a char, but in this scenario there wasn&#039;t a better option really.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Normalise it.  Store timestamped occurrences in another table, associated to the events table by a foreign key.&lt;/p&gt;
 </description>
     <pubDate>Sat, 11 Apr 2009 02:41:00 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1240307 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Hmm I do need it for a</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240303</link>
    <description> &lt;p&gt;Hmm I do need it for a condition for data from mysql, but cannot use it in the query here. &lt;/p&gt;
&lt;p&gt;As the events can occur over multiple days, and therefore potentially 2 months &amp;amp; two years (Dec 28 to Jan 5), I have multiple timestamps for each event. The event has no true limit for days it could span to allow for a set total sql field allowance, so I enter them in one field with a delimiter, then splitting at the delimiter and the largest timestamp for the split is taken as the &quot;latest&quot;.&lt;/p&gt;
&lt;p&gt;Otherwise that may have been useful .&lt;/p&gt;
&lt;p&gt;I don&#039;t like using one field for multiple stuff and then splitting by a char, but in this scenario there wasn&#039;t a better option really.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Fri, 10 Apr 2009 21:53:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1240303 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Just to let you know, if you</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-timestamp-minus-24-hours#comment-1240302</link>
    <description> &lt;p&gt;Just to let you know, if you are needing it for a condition for data to be returned, you can do this in the SQL statement. It is best practice to do as much processing of the data the SQL server before getting data.&lt;/p&gt;
&lt;p&gt;Here is the method I usually use, and there are many ways, so this is just my preference. &lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add&quot; title=&quot;http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add&quot;&gt;http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#func...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Fri, 10 Apr 2009 21:27:06 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1240302 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
