title: database query retuyrns fields in one order, I want to display them in another
body: <p>This probably has been answered (or should be basic knowledge), so please forgive the noob question...</p>
  
  <p>I'm using the WP user_meta database to store advanced properties of a user.</p>
  
  <p>Data is stored in this order (this is all for userid=15):</p>
  
  <pre><code>city = Altoona
  state = PA
  phone = 9999999999
  name = Fred
  
  I want to generate the output as
  Fred, Altoona, PA, 9999999999
  </code></pre>
  
  <p>Here's the relevant PHP code:</p>
  
  <pre><code> $my_exportlist = $wpdb-&gt;get_results("SELECT `user_id` FROM `wp_m_membership_relationships` WHERE `level_id` = '2' ");
  foreach ($my_exportlist as $duser) {
  
  $my_stationinfo = $wpdb-&gt;get_results("SELECT * FROM `wp_usermeta` WHERE `meta_key` IN ('name', 'city', 'state', 'office') AND user_id ='$duser-&gt;user_id'");
  
  foreach ($my_stationinfo as $myinfo) {
      $csv_output .= $myinfo-&gt;meta_value . ",";
      }
  $csv_output .= "\n";
  }
  </code></pre>
  
  <p>After the first answer I did this:</p>
  
  <pre><code>$my_stationinfo = $wpdb-&gt;get_results("GROUP_CONCAT(meta_value) val_output
          FROM `wp_usermeta`
          WHERE `meta_key` IN ('name', 'city', 'state', 'office') AND user_id ='$duser-&gt;user_id'
          ORDER BY FIELD(meta_key, 'name', 'city', 'state', 'office'");
  </code></pre>
  
  <p>I get this error message...</p>
  
  <pre><code>WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP_CONCAT(meta_value) val_output FROM `wp_usermeta` WHERE `meta_key' at line 1]
  </code></pre>
  
  <p>and after looking at a number of q/a and the linked mySQL instrucitons, I'm still baffled....</p>
  
  <p>Further followup:
  This is the current code </p>
  
  <pre><code>   $my_exportlist = $wpdb-&gt;get_results("SELECT `user_id` FROM `wp_m_membership_relationships` WHERE `level_id` = '2' ");
  foreach ($my_exportlist as $duser) {
  
  $my_stationinfo = $wpdb-&gt;get_results(
      "SELECT GROUP_CONCAT(meta_value) val_output
          FROM   wp_usermeta 
          WHERE  meta_key IN ('primary_calls', 'city', 'state', 'office', 'contact_emerg', 'contact_routine', 'contact_backup', 'contact_billing', 'contact_eng', 'contact_web', 'contact_prod', 'contact_traffic') AND
                 user_id = '$duser-&gt;user_id'
                 ORDER BY FIELD(meta_key, 'primary_calls', 'city', 'primary_calls','state', 'office', 'contact_emerg', 'contact_routine', 'contact_backup', 'contact_billing', 'contact_eng', 'contact_web', 'contact_prod', 'contact_traffic')");
  print_r($my_stationinfo);
  var_dump($my_stationinfo);
  echo $my_stationinfo-&gt;val_output[0] ;
  
  
  foreach ($my_stationinfo as $myinfo) {
  
      $csv_output .= $myinfo;
  }
  $csv_output .= "\n";
  </code></pre>
  
  <p>The results:</p>
  
  <pre><code>Array ( [0] =&gt; stdClass Object ( [val_output] =&gt; Altoona,PA,814.943.8112,WRTA ) )
  
  
  array
    0 =&gt; 
      object(stdClass)[5]
        public 'val_output' =&gt; string 'Altoona,PA,814.943.8112,WRTA' (length=28)
  
  
  Notice: Trying to get property of non-object in D:\Users\Dev\Documents\Websites\contract.dev\wp-content\plugins\custom_plugin\index_page.php on line 40
  
  Catchable fatal error: Object of class stdClass could not be converted to string in D:\Users\Dev\Documents\Websites\contract.dev\wp-content\plugins\custom_plugin\index_page.php on line 45
  </code></pre>