Insert large amount of rows from array to database with PHP and MySQL

This is how you can insert a large amount of rows from an array in PHP using only one call to MySQL instead of doing a loop with foreach and call MySQL for every row.

Note: db_query() is for Drupal, but the basic concept works in plain PHP/MySQL:

INSERT INTO parser_queue (sid, nid) SELECT id AS sid, 109 AS nid FROM source_109 WHERE id IN (1,2,3);


PHP, strtotime and weeks over new year problems

Having problems with navigating over new year with weeks and think it's a bug? You are not alone, a friend of mine also thought so :-) There is a problem how to deal with starting days of week, Sunday or Monday causing the problem.

Problem: based on a date adding a week or 7 days (+1 week or +7 days) causing "20121224 +1week" end up on "20121231" if you set "Ymd" but if you go for "YW" you get "201201". If you instead use the ISO year "o" you will get the right year.

Random HTML color code for charts

When you do stack charts, it is important that the colors differ so much from each other that they are not mixed up. I made a function that returns a predetermined number of color codes that I've tested that is not too similar to each other.

When these color codes ends, a random number generator creates new color codes, these are not controlled, but my tests shows that it will do well.

Maybe I am doing a new feature one day that randomly generates an indefinite series of colors that can lie next to each other without being mixed up.

How to encrypt and decrypt URL when using GET

This is one example on how to encrypt and decrypt the URL in your system. You can't use this if you are using Drupals menu system where a certain segment should be the encrypted part because this encrypted string can contain slashes and make the call and arguments distributed in an uncontrolled way.

Your planned URL:

...can end up like:

But if you send it like a GET value it works like a sharm.