Monday, July 28, 2008

array_merge_recursive error

Today, I ran into a problem with Drupal, when in the admin page, I see this message on top of the page:
array_merge_recursive() [function.array-merge-recursive]: recursion detected

The reason why this was show up because"

is put into xxx_menu hook.

The best practice is to put that into the xxx_init() function.

Tuesday, July 22, 2008


Just find this article great on the different between PHP4 and PHP5.

Monday, July 21, 2008

Cool and easy way to find timestamp

I just find this is cool and useful when try to try a timestamp for particular date in PHP. Of course, there are many ways to do it, but may you find this one quick and easy in PHP.

echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";


When using "COUNT" and "GROUP BY" in mysql, make sure that the count condition to run after group by, otherwise the sql will fail.

SELECT count(node.uid) as num, node.uid,
node.created AS node_created
FROM node
WHERE (node.type in ('advisor_update')) AND (node.status <> 0)
AND num > 2
GROUP BY node.uid
ORDER BY node_created DESC;

SELECT count(node.uid) as num, node.uid,
node.created AS node_created
FROM node
WHERE (node.type in ('advisor_update')) AND (node.status <> 0)
GROUP BY node.uid
HAVING num > 2
ORDER BY node_created DESC;

The fist statement will fail, use the 2nd statement instead.

Friday, July 18, 2008

String Index using string[index] or string.charAt(index)

I found this issue today on string index of javascript for IE 7.

It seems like IE7 does't like String[index] at all, but it works with string.charAt(indext).

Try this out:

function memberlink_txtchange(id){
var value = $('#'+id).val();
var int_var;
var new_var = '';
for(var i = 0; i < value.length; i++){
new_var += value.charAt(i);

return true;

Drupal write query relate to revision control

When write sql in drupal that related to revision control, the best practice is ONLY use nid in the node table, for the rest of the tables, use vid instead. That will prevent contents from syn. See this example for reference:

$query ="SELECT DISTINCT n.nid FROM content_type_event e
INNER JOIN node n ON n.nid = e.nid
INNER JOIN content_field_feature cff ON cff.vid = n.vid
INNER JOIN content_field_date_and_time cfdt ON cfdt.vid = n.vid
WHERE n.status = '1' AND = '0'
AND cff.field_feature_value ='1'
ORDER BY cfdt.field_date_and_time_value ASC LIMIT 2";