my sql query returns empty

$sql = $wpdb->get_results('SELECT * from table1 WHERE id = ' .$bransId);

And im sure that $bransId is not empty. ( i checked)

  • Did you define global $wpdb? Does the table1 exist? Does the id exist in that table?
    – Emetrop
    Jul 20, 2015 at 22:01

1 Answer 1


If you can answer 'yes' to the questions in Emetrop's comment, then try:

$sql = $wpdb->get_results('SELECT * from table1 WHERE id = $bransId');
  • 1
    I'm afraid this won't work, since the variable isn't inside double quotes. Additionally we shouldn't trust the user input and use $wpdb->prepare().
    – birgire
    Jul 21, 2015 at 0:58

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.