0
$country="USA";
$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.

6
  • 3
    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. Commented Oct 28, 2013 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
    Commented Oct 28, 2013 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. Commented Oct 28, 2013 at 6:31
  • Please follow up answers to your questions.
    – kaiser
    Commented Oct 30, 2013 at 9:01
  • @ kaiser ofcourse i'll but i don't why are u pointing me here
    – Monika
    Commented Oct 30, 2013 at 12:01

1 Answer 1

1

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(
    $wpdb->prepare(
        "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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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