2010-03-26 59 views
0

我試圖讓這個工作和查詢執行,但沒有回來。我試過了我能想到的一切,你能發現我做錯了什麼嗎?Drupal db_query_range SQL查詢

$nido = $node->nid; 
$result = db_query_range(' 
     SELECT i.nid, i.iid, a.fid, p.filename, p.filepath 
     FROM {drup_image_attach} i 
     LEFT JOIN {drup_image} a ON i.iid = a.nid 
     LEFT JOIN {drup_files} p ON a.fid = p.fid 
     WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nido, 0, 10); 
echo "Filepath = " . $result ->filepath. "<br>"; 
echo "Filepath = " . $result ->filename . "<br>"; 
echo "IID = " . $result ->iid. "<br>"; 
echo "NID = " . $result ->nid . "<br>"; 
} 

編輯 - 我整理了幾位,但輸出仍然是空的!

編輯 - 這是工作代碼:

$nodeid = $node->nid; 
$get_image = db_query(' 
    SELECT p.filepath as imagefilename 
    FROM {image_attach} i 
    LEFT JOIN {image} a ON i.iid = a.nid 
    LEFT JOIN {files} p ON a.fid = p.fid 
    WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nodeid); 
$obj_image = db_fetch_object($get_image); 
$imagefilename = $obj_image->imagefilename; 

回答

2

$result只是一個MySQL(我)資源。您首先必須獲取行/對象。

$result = db_query_range(....); 
$object = db_fetch_object($result); 
print_r $object; 
+0

嗯......也許有東西在SQL ..我非常想放棄的Drupal DAL,只是做在純PHP/SQL tbh! – MrFidge 2010-03-26 14:11:11

+0

hiya - 得到它的工作,感謝您的對象提示:) – MrFidge 2010-03-29 16:28:29

0

假設你有一個範圍OB結果而不是一個單一的結果這應該工作。您需要將結果存儲在數組中或以不同的方式處理它們。對於單個結果看db_result(),它似乎並沒有幫助

$nodeid = $node->nid; 

$get_image = db_query(' 
    SELECT p.filepath as imagefilename 
    FROM {image_attach} i 
    LEFT JOIN {image} a ON i.iid = a.nid 
    LEFT JOIN {files} p ON a.fid = p.fid 
    WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nodeid); 

while(($obj_image = db_fetch_object($obj_image)) == TRUE){ 
    $imagefilename[] = $obj_image->imagefilename; 
}