How should I load a node with its images programatically? I want to load a node with its images in Drupal 7, such as using the following code:

  $current_node = node_load(arg(1));
  db_query("SELECT nid, title FROM {node} WHERE type = :type AND created &lt; :created LIMIT 1", array(':type' =&gt;  $current_node-&gt;type, ':created' =&gt; $current_node-&gt;created))-&gt;fetchObject()


I wish to load the image field in the content; I think I should use left join to load the image file.

Does anybody know what to do next? What is the image table name?
You're going to have to join another table for every field that you want to grab the data for, which is just a pain. Instead, you could just get the nid with your query, and use node_load() a second time to get the other node object, complete with attached fields.

You can do that like so:

$args = array(':type' =&gt; $current_node-&gt;type, ':created' =&gt; $current_node-&gt;created);
$sql = 'SELECT nid FROM {node} WHERE type = :type AND created &lt; :created';
$nid = db_query_range($sql, 0, 1, $args)-&gt;fetchField();

$new_node = node_load($nid);

$title = $node-&gt;title;
$image_field_values = field_get_items('node', $new_node, 'field_image');

$first_image = array_shift($image_field_values);
$image_file = file_load($first_image['fid']);

$image_html = theme('image_style', array(
  'style_name' =&gt; 'thumbnail',
  'path' =&gt; $image_file-&gt;uri,
  'alt' =&gt; 'Some alt text'
));

$body_values = field_get_items('node', $new_node, 'body');

// And so on