我已经在Drupal 7中使用简单查询完成了我的数据库操作。但是我想要使用 Drupal 7 theme_table 进行一些分页功能,因为我必须使用 Drupal 7 db_select ,但我无法这样做。
请尽快帮助我,下面是 mysql 查询我想要转换为db_select : -
SELECT r.ROName, CONCAT(CONCAT(CONCAT(r.Address1, ' - ' , r.Pincode),' - ',d.Distname),' - ',s.StateName) as Address1,r.Phone1, r.Phone2, r.Fax, r.Phone3, r.Pincode, r.DistID,d.Distname, d.DistID, s.StateID, r.StateID, s.StateName
FROM ROMaster r
JOIN DistrictMaster d ON r.DistID = d.DistID JOIN StateMaster s ON r.StateID = s.StateID
WHERE SBUID =1
ORDER BY r.ROName
答案 0 :(得分:1)
这样的事情,我想:
$query = db_select('ROMaster', "r");
$query->innerJoin("DistrictMaster", "d", "r.DistID=d.DistID");
$query->innerJoin("StateMaster", "s", "r.StateID = s.StateID");
$query->addField('r', 'ROName');
$query->addExpression('CONCAT(CONCAT(CONCAT(r.Address1, ' - ' ,
r.Pincode), ' - ',d.Distname),' - ',s.StateName) as Address1')
$query->addField('r', 'Phone1');
$query->addField("r", "Phone2");
$query->addField("r", "Fax");
$query->addField("r", "Phone3");
$query->addField("r", "Pincode");
$query->addField("r", "DistID");
$query->addField("d", "Distname");
$query->addField("d", "DistID");
$query->addField("s", "StateID");
$query->addField("r", "StateID");
$query->addField("s", "StateNam");
$query->condition("SBUID", 1);
$query->orderBy("ORDER BY r.ROName");
$result = $query->execute();