Wednesday, November 21, 2012

HTML5 Drag and Drop example tested in Chrome,IE(7-9),FF

I was looking for HTML5 drag and drop example on google so i came across w3schools example and the code worked fine on their own online editor. Then i copied the same code inside an html file that i created locally on my system. After running local html file inside different browsers the script went against my expectations and refused to work inside IE.

I went back to w3schools editor with the working code and checked if any extra javascript code was included but found nothing additional there.

I was a bit disappointed and returned back to my local script. I had no option but to find the solutions for IE errors. When i googled the errors, it occured the methods used inside javascript code were not available inside IE. Anyway i debugged the code and fixed all the IE specific errors which took exceptional time. Thanks to IE developer tool that helped me a lot and thanks to w3schools example who led me to the errors.

After wasting lot of time in fixing w3schools example i thought why not i put it on my blog so that someone else's time would not be wasted. Hope this helps.

Below link has the example script.

Friday, November 9, 2012

MySQL Function to Calculate x time ago from a particular date

Couple of days ago i was searching for a function in MySQL that could calculate time difference of a particular time with current time and return string like "3 minutes ago" or "2 days ago" and etc. I came across many functions for PHP but no MySQL. So i picked a PHP function and converted it to MySQL function. I used the PHP script from by Tom Elliot.

MySQL script to create this function is


DROP FUNCTION IF EXISTS `fn_x_time_ago`$$

CREATE DEFINER=`root`@`localhost` FUNCTION `fn_x_time_ago`(old_time DATETIME) RETURNS VARCHAR(100) CHARSET latin1
DECLARE the_result VARCHAR(100) DEFAULT '';
DECLARE time_difference INT(11);

IF (time_difference > (60*60*24))
THEN SELECT CONCAT(ROUND(time_difference/60/60/24)," days ago") INTO the_result;
ELSEIF (time_difference > (60*60))
THEN SELECT CONCAT(ROUND(time_difference/60/60)," hours ago") INTO the_result;
ELSEIF (time_difference > (60))
THEN SELECT CONCAT(ROUND(time_difference/60)," minutes ago") INTO the_result;
ELSEIF (time_difference > (0))
THEN SELECT CONCAT(time_difference," seconds ago") INTO the_result;
RETURN the_result;


Name of MySQL function is fn_x_time_ago. It takes a date as argument. So the query to call this function will become.

SELECT fn_x_time_ago('2012-11-10 10:15:00');