WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a database query as below:

$id = $_GET['id'];
$query = 'select * from ';
$query .= $wpdb->get_blog_prefix() . 'fxdescription ';
$query .= 'where id= '.$id;
$currency = $wpdb->get_results( $wpdb->prepare( $query ), ARRAY_A );

The result of doing print_r($currency) is as below:

Array ( 
[0] => Array ( [id] => 1 [code] => EUR [name] => Euro [description] => [format] => direct ) 

The question is - is the above result normal, as the result is an array inside an array, and to access the data I have to use $currency['0']['code'], in place of $currency['code']?

share|improve this question
Side note: I do like this echo '<pre>' . print_r( $currency, true) . '</pre>' to get an easier to read output. – brasofilo Nov 18 '12 at 11:32
  1. its normal for get_results method
  2. you can use get_row method to get only one row.
share|improve this answer
Thanks for the help. Tried get_row method, and it worked perfectly. – Deepak Kundu Nov 18 '12 at 11:27

No, the default output type of get_results is object, but you've set it to associative arrays.

Yes, you'll need to use $currency[0]['code'], or you could use

foreach ( $currency as $c ) {
    echo $c['code']; // can now be accessed
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.