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
$dr=$wpdb->get_results("SELECT $country FROM wp_shipping WHERE ID=$ids");

I want the above query in WordPress file, where country name is given dynamically but I am not getting how to do this. When I execute the above query, the result is nothing.

share|improve this question
your SQL is wrong, and it is more of an SQL question then a wordress one. The way I debug SQL is by running queries in phpmyadmin when I think that my code should work but it doesn't. – Mark Kaplun Oct 28 '13 at 6:22
I am using this query in wordpress that is why i have asked this question here. And i want help that where i am wrong? – Monika Oct 28 '13 at 6:25
told you where you are wrong, and I want to date a super model :). Basically if it is not related to understanding the usage of wordress API then the question will have a better chance of being answered in other places. in your case you need an SQL help not a wordpress help. – Mark Kaplun Oct 28 '13 at 6:31
ok. thanks@ Mark Kaplun – Monika Oct 28 '13 at 7:02
Please follow up answers to your questions. – kaiser Oct 30 '13 at 9:01

I guess one could argue that this is somewhat wordpress related, because you are trying to get_results() from $wpdb, but like @MarkKaplun said your problem is that you are using the SQL wrong. Below code is an example on how to do it correct:

$dr = $wpdb->get_results(
        "SELECT * FROM wp_shipping WHERE country = %s AND ID = %d",
        $country, $ids

This is an example, you might have to fit it to your needs. For additional information you should take a closer look at the codex Class Reference: wpdb.

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.