0

Trying to write a prepare statement that works. This works:

$countthem = $wpdb->get_var( "SELECT COUNT(*) FROM wp_cmapg WHERE lang = 'yes'" );

This does NOT work:

$countthem = $wpdb->get_var(
    $wpdb->prepare( "SELECT COUNT(*) FROM wp_cmapg WHERE lang= %s", $lang ), 0, 0 
);

Also tried:

$countthem = $wpdb->get_var(
    $wpdb->prepare( "SELECT COUNT(*) FROM wp_cmapg WHERE lang LIKE %%%s%%", $lang ), 0, 0 
);

The contents of $lang is yes.

1

Try adding the single quotes back around the %s:

$countthem = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_cmapg WHERE lang='%s'", $lang) );
  • If the answer worked for you, the best thank you is to accept it (click the check mark under the vote arrows on the left), and once you have enough reputation, you can also vote up answers that are helpful. – Gabriel Apr 25 '16 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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