Category: PHP/JS/MySQL Scripting

How to solve inconsistent PHP times 0

How to solve inconsistent PHP times

Most likely, the issue is with your php server randomly choosing a timezone and therefore having times which are usually either one hour behind or one hour after..

To solve it, right before the ‘mission critical’ area of your script, use date_default_timezone_set() .

An example of this is

date_default_timezone_set('America/Dominica');

Note: you can test your timezone with

echo date_default_timezone_get();

 

How to add and subtract fom time in MySQL 0

How to add and subtract fom time in MySQL

Luckily for us there is an ADDTIME function we can use to add and remove from times… The syntax is as follows: ADDTIME(datetime,time_to_change) example

SELECT `emp_id` , `clock_time` , ADDTIME( '-01:00:00', `clock_time` ) AS new_time
FROM `timeclock`

Will return

emp_id clock_time new_time
10059 08:30:55 07:30:55
10059 08:31:06 07:31:06
10059 08:31:28 07:31:28
10046 08:33:44 07:33:44

An Update example

UPDATE `timeclock` SET `clock_time` = ADDTIME( '-01:00:00', `clock_time` ) WHERE `id` BETWEEN 40967 AND 41022
0

How to get mssql to work on php (debian/ubuntu)

Assuming that you already have PHP installed, you enter into the console

 apt-get install php5-sybase

(sadly not as intuitive as apt-get install php5-mssql)

For most instances that may be enough to give you what you need. If by any chance that doesn’t work, or you need more ‘functionality’ you can try (untested by me)

apt-get install php-pear
pear install --nodeps MDB2_Driver_mssql
How to create a ‘select all’ checkbox in javascript 0

How to create a ‘select all’ checkbox in javascript

For HTML Code:

<input type="checkbox" onClick="toggle(this)" />

<input type='checkbox' name='ss' value='one'  />
<input type='checkbox' name='ss' value='two'  />
<input type='checkbox' name='ss' value='three'  />

We use Javascript:

<script>
  function toggle(source) {
    checkboxes = document.getElementsByName('ss');
    for (var i = 0, n = checkboxes.length; i < n; i++) {
      checkboxes[i].checked = source.checked;
    }
  }
</script>

(more…)