db_query() to retrieve the image path using the fid In Drupal 7, I'm trying to retrieve the image path for a given fid.

If I am running a query such as the following, that is fine and dandy and returns a bunch of numbers that relate to the images on each row. 

$query = db_query("Select s.field_swatch_image_fid as fid from {field_data_field_swatch_image} s");

foreach ($query as $row) {                    
  $swatch_fid =&gt; $row-&gt;fid .'&lt;br /&gt;'; 
}


However, the table contains no information as to how to retrieve the actual image. Does anyone know the secret to pull the actual image URL into the foreach loop, or is there some sort of render function that needs to be run on the fid values? I'm guessing it is easy, but I can't seem to find any documentation on this.

Also, if I wanted to apply a style to the images, would that be a necessary step if the style was already set on the field image itself, and if so, what would be that process?

EDIT:
here is the full query. I was doing it manually because I have to retrieve the value and send a json object back to jquery and then render it in jquery. But this is kindof the start to a different and larger question. 

Declare database variables to be used in the database call 
 - so far this was easier than looking at all the giant field names Drupal creates in the database
 - hoping to rewrite the query in the new improved drupal 7 style soon



*/

  $swatchcolor = "field_data_field_swatch_color";  // sc - swatch color data table
  $color = "field_swatch_color_value";
  $states = "field_data_field_state"; // s the table that holds the swatch's reference to the state
  $state = "field_state_value";
  $swatchref = "field_data_field_swatch_ref"; // sr - swatch reference target table
  $target = "field_swatch_ref_target_id";
  $imagetable = "field_data_field_swatch_image"; // swatch image ref
  $parent_ref = "field_product_ref_target_id";
  // If a swatch has not been selected, run this query and select all colors as options

  if($swc == '') {


    $query = db_query ("Select n.nid AS nid, n.title AS title, s.$state AS state
        FROM {node} n
        INNER JOIN {$swatchref} sr ON sr.$target = n.nid
        INNER JOIN {$states} s ON s.entity_id = sr.entity_id
        WHERE (s.$state IN $theregion)
        GROUP BY title");


  } else {

      $query = db_query ("Select n.nid AS nid, n.title AS title, sc.$color AS color, s.$state AS state
        FROM {node} n
        INNER JOIN {$swatchcolor} sc ON sc.entity_id = n.nid
        INNER JOIN {$swatchref} sr ON sr.$target = n.nid
        INNER JOIN {$states} s ON s.entity_id = sr.entity_id
        WHERE (sc.$color = '$swc') AND (s.$state IN $theregion)
        GROUP BY title");

  }




EDIT!!
Here is how the image path was integrated into the json output:

 $json = array();
        foreach ($query as $row) {

        // get the image fid 

          $fid = $row-&gt;thefid;
          $file = file_load($fid);
          // $file = str_replace('public:\/\/', '', $file1);

        // create the output as an array
          $jsonelement=array(

             'title' =&gt; $row-&gt;title,
             'path' =&gt; $file-&gt;uri,
             'style_name' =&gt; 'swatch'

            );
              array_push($json,$jsonelement);   
        } 

            // encode to json
            $jsonstring = drupal_json_encode($json);

            //output the json string
            drupal_json_output($jsonstring);
There is no need for manual queries.

You can load a file using file_load($fid), and then the path is in $file-&gt;uri. It might look a bit stringe ('public://something.jpg'), but that's a so called stream wrapper, and it works just fine with plain PHP file functions. 

It's not exactly clear to me what you are trying to achieve; if you want to render an image field from a node/user/..., there are better ways to embed title and things like that, but this would work if you really just have a field. (That you are trying to query the field data table suggests otherwise, though.)

&lt;?php
  $file = file_load($fid);
  $variables = array(
    'path' =&gt; $file-&gt;uri,
    'style_name' =&gt; 'your_style_name',
  );
  print theme('image_style', $variables);
?&gt;