如何在drupal中编写sql LIKE查询,
- SELECT title FROM { node } WHERE type='%s'
我想在这里添加喜欢的条件
- SELECT title FROM { node } WHERE type='%s' AND LIKE '%S%'
我认为我写错了像查询formnat,可以重写并告诉我,
解决方法
只需使用%即可逃脱.
- $result = db_query('SELECT title FROM {node} WHERE type = "%s" AND title LIKE "%%%s%%"','type','title');
- while ($row = db_fetch_object($result)) {
- // do stuff with the data
- }
节点类型不需要转义.