2015-10-02 73 views
0

https://www.codeenigma.com/community/blog/drupal-7-cheat-sheet-database https://www.drupal.org/update/modules/6/7Drupal 7的獲取相當於

我無法從Drupal的6包住我的頭周圍的變化 - > 7.

"SELECT CRS_sales.User, CRS_Goals.*, 
sum(CRS_sales.CompUnits) as CompUnits, 
sum(CRS_sales.KBUnits) as KBUnits, 
sum(CRS_sales.PrinterUnits) as PrinterUnits, 
sum(CRS_sales.MouseUnits) as MouseUnits, 
Count(CRS_sales.Comp) as CompCount 
sum(CRS_sales.CompUnits + CRS_sales.KBUnits + CRS_sales.PrinterUnits + CRS_sales.MouseUnits) as UnitsTotal, 
FROM CRS_sales 
INNER JOIN CRS_Goals 
ON CRS_sales.User=CRS_Goals.User 
WHERE date(CRS_sales.Created) = "01/10/2015" GROUP BY CRS_sales.User 
order by UnitsTotal DESC"; 

我如何獲取這些信息儘可能多的行存在?

謝謝你的幫助。

+0

的Drupal提供db_query($查詢)方法。你可以簡單地傳遞你的查詢。雖然這個方法也存在於drupal 6中。 –

回答

0

您可以將此SQL傳遞給db_query()函數以從數據庫獲取數據。

0

使用db_query函數,例如

$result = db_query("your sql here"); 
$data = $result->fetchAll(); 

如果您的查詢使用用戶數據,你應該清理它通過Drupal的佔位符 https://www.drupal.org/writing-secure-code