From array to HTML table - very simple
This is a very simple function to create a HTML table from an array. Some things are even hardcoded but can easily be either changed or modified to be more generic.
This is a very simple function to create a HTML table from an array. Some things are even hardcoded but can easily be either changed or modified to be more generic.
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);
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.
This is a simple test script to check if the server can send mail using PHP, just change the receiver address.
<?php
$to = "<a href="mailto:my.name@gmail.com">my.name@gmail.com</a>";
$subject = "Test";
$body = "Hi,\n\nThis is a test.";
if (mail($to, $subject, $body)) {
echo("<p>Message sent!</p>");
} else {
echo("<p>Message failed!</p>");
}
?>
This is how you can get the MAC address from Linux server with PHP when you need to find out the host for licence etc.
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.
This is how you can get the week starting date or ending date by giving a week number and the year.
This code validates e-mail address with regular expression. This code is from Drupal 6 common.inc.
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:
mysite.se/mymodulepath/EnCrYptedParTOne/EnCrYptedParTTwo
...can end up like:
mysite.se/mymodulepath/EnCrYpt/dParTOne/EnC//YptedParTTwo
But if you send it like a GET value it works like a sharm.