How do I change the output of a database query from an integer to a string? I'm working on a module that has a form that that submits to a database table and then queries that database to place that information in a table on another page. Everything works like I want with the exception of the 'country' entry which is a select box on the form and returns a numeric value (0,1,2, or 3). I would like to display in the table the text of the country instead of the numeric value. I have tried elseif statements and arrays and have been able to get the text string to display on the page but not replace the number in the table. I just learning to write modules and any insight would be greatly appreciated.

function drupalform_form1_submit($form, $form_state) {
  $d_id = db_insert('drupalform')
    -&gt;fields(array(
      'name' =&gt; $form_state['values']['name'],
      'last_name' =&gt; $form_state['values']['last_name'],
      'email' =&gt; $form_state['values']['email'],
      'country' =&gt; $form_state['values']['country'],
    ))
    -&gt;execute();
   drupal_set_message("Form has been submitted");
}

function drupalform_submissions() {
  $query = db_select('drupalform', 'df_list');
  $query
    -&gt;fields('df_list', array('d_id', 'name', 'last_name', 'email', 'country'))
    -&gt;range(0, 50)
    -&gt;orderBy('df_list.d_id');
  $results = $query-&gt;execute(); 

  $header = array(t('ID'), t('First Name'), t('Last Name'), t('Email'), t('Country'));
  $rows = array();

  foreach ($results AS $result) {
    $rows[] = array(
      check_plain($result-&gt;d_id),
      check_plain($result-&gt;name),
      check_plain($result-&gt;last_name),
      check_plain($result-&gt;email),
      $result-&gt;country,
    );   
  }

  return theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
}
The numeric value from the country is essentially a database lookup value to either a Taxonomy Term, a Countries entry ... or whatever module you're using to reference the location. This is typical DB usage, store keys -- not (text) values of the data. If it was a taxonomy term you could do:

function drupalform_form1_submit($form, $form_state) {

  // Lookup the value for the country id key, somewhere, here I assume Taxonomy.
  $country_term = taxonomy_term_load($form_state['values']['country']);
  $d_id = db_insert('drupalform')
    -&gt;fields(array(
      'name' =&gt; $form_state['values']['name'],
      'last_name' =&gt; $form_state['values']['last_name'],
      'email' =&gt; $form_state['values']['email'],
      // Store the country text value, for Taxonomy Terms thats the name value of the object.
      'country' =&gt; $country_term-&gt;name,
    ))
    -&gt;execute();
   drupal_set_message("Form has been submitted");
}


Assuming your using Taxonomy Terms as countries, and the TID is in only 1 Taxonomy. You would use the same approach with any 3rd party location module.