2011/03/09

DRUPAL 7中能夠TRIM Teaser的地方

今日搵了很久, 為何在content type 的teaser選了trim length, 但frontend 仍然不見效果..

原來我除了在content type trim了,還在 views 裏的"field"  再trim了一次, 例如在content type set 了length 300: , 之後pass到view裏即使set 到trim 350也沒有效果, 因為一早被content type的override了!

當一個node 經panels, views ,block 顯示既時候, 真的要set好rule 搞清楚次序, 因為太多setting 可以互相override, 見一個set一次的話之後debug就頭痛了..

關於module 互相override的次序, 其實都可以check得番, 就係去database 睇"system"既table, 睇番你想睇既module, 留意weight, 通常會係0, views既default 係10 , 通常taxonamy, node 等等都會被view override 

但對於node .tpl file 同view 比較, 好似node .tpl file 永遠係最高prority, 這個有待確認

2011/03/08

sql ifnull

如果sql 要用concat 但又有null, 咁 ifnull 就好好用了
因為concat null 會成個value 變null 的

SELECT CONCAT(IFNULL(FIRSTNAME, ''), ' ', IFNULL(LASTNAME, '') AS FULLNAME FROM USER;

sql group_concat group by

今日先知原來有group_concat
會自動將那個column 的value 用 ',' group
完全救左我~!!

SELECT Class, GROUP_CONCAT(Animal) AS Animal FROM Zoo GROUP BY Family;

table
Class   Animal
===========
Fish   Goldfish
Fish   Grouper
Mammal Tiger
Mammal Lion


Result:
Fish   Goldfish,Grouper
Mammal  Tiger,Lion

"Update" SQL joining more than 1 tables

平時用CODE做, UPDATE SQL 都係好簡單, 但如果想做複雜少少既UPDATE, 其實亦可以COMBINE 埋 SELECT 一齊UPDATE , 但個SYNTAX有少少唔同

假設我select 左一堆node type係 "recipe" ,同profile_values 係"member"既row出黎

select * from node ,users ,profile_values 
where node.type='recipe' 
and users.uid = node.uid 
and profile_values.nid = node.nid
and profile_values.value='member'

之後我想將result 既某一個column (e.g. language )一次過update做新value
update node ,users ,profile_values 
set node.language ='sc_kit_cn' 
where node.type='recipe' and users.uid = node.uid 
and profile_values.nid = node.nid
and profile_values.value='member'

簡單講, 
就係將from 既table list 放去update後面
set 既column一定要簡番要update既table
where 果堆照keep番