tags:

views:

249

answers:

1

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 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  A: 

$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;
Paul
hmm that doesn't appear to have helped... maybe there is something in the SQL.. I'm sorely tempted to abandon the Drupal DAL and just do it in plain PHP/SQL tbh!
hfidgen
hiya - got it working, thanks for your object tip :)
hfidgen