开发者

Drupal db_query_range SQL query

I'm trying to get this working and the query executes but nothing comes back. I've tried everything I can think of, can you spot what I'm doing wrong?

$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>";
}

EDIT - I sorted out a couple of bits, but the output is still empty!

EDIT - this is the working code:

$nodeid = $node->nid;
$get_image = db_query('
    SELECT p.filepath as imagefilen开发者_如何学Goame
    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;


$result is a mysql(i) resource only. You first have to fetch the row/object.

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


Assuming you have a range ob results not a single result this should work. You need to store the results in an array or process them in a different manner. for a single result see 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜