I am attempting to make a simple database query -- the problem is that "db_fetch_array" returns and empty array -- and "db_fetch_object" returns the last value in the array. What I need is the first value in the array.

From my review of the forum these functions tend to be problematic -- any assistance in pointing me in a direction which would allow me to resolve this issue would be greatly appreciated. Thanks

Current code:

// get thumbpath from node_images table
$image = array(); //just an empty array
$image_sql = db_query('SELECT * FROM {node_images} WHERE nid = %d', $node->nid);
while ($img = db_fetch_object($image_sql)){
$variables['image'] = $img->thumbpath;
}

Note: I have tried to utilize the count and list functions but I recieve an error message of no object or array.

Comments

nimrod98’s picture

Hi,
If you are doing db_fetch_array, did you type $img['thumbpath'] instead of $img->thumbpath? Perhaps you can try to show what the value is by either echo $img['thumbpath'] or drupal_set_message if it is in a module.

auctionteamster’s picture

Thanks - but same result with $img['thumbpath']