Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Thursday, May 28, 2009

Incorrect usage of UNION and ORDER BY

A common problem when using the UNION command in MySQL is when you want to order the sets of data differently. If you do it incorrectly, you will see the error message:

Incorrect usage of UNION and ORDER BY


To solve the problem, wrap each individual SELECT statement in brackets as shown below:

(SELECT * FROM table1)
UNION
(SELECT * FROM table2)

Monday, May 25, 2009

How to group by a datetime field in mysql

SELECT YEAR(datefield) Y, MONTH(datefield) M, DAY(datefield) D FROM yourtable
GROUP BY DAY(datefield)

Tuesday, May 19, 2009

PHP: Calculate Number of days between dates

Now that timestamps have been reviewed to show you some easy way to take two days and return a total number of days. The example below will take an arbitrary date of April 4, 2008 and May 12, 2008 (the current date I wrote the article)

$time_A = strtotime("April 4, 2008"); $time_B=strtotime(now); $numdays=intval(($time_B-$time_A)/86400)+1;

The number of seconds in a day is 86400 and the calculations usually shorts you a day so thats why we add a 1. This is do the fact the now() returns the current time which is not a complete day. 

source: http://www.bswebdev.com/2008/05/php-day-count-and-date-comparison/


Chitika Ads