Reputation: 1244
One of the fields in the mysql database is 'TIME' type, formatted 'H:i:s'. When querying the database with the field value set, like:
$result = $wpdb->get_var($wpdb->prepare("SELECT * FROM table WHERE start_hour='06:00:00'", ARRAY_A));
Everything works great. But when I replace it with a variable like this:
$stime = '06:00:00';
$result = $wpdb->get_var($wpdb->prepare("SELECT * FROM table WHERE start_hour=$stime", ARRAY_A));
$result comes up empty. I've been messing about with the formatting of $stime, but am coming up empty.
Upvotes: 0
Views: 91
Reputation: 12042
You're missing single quotes around $stime
in your second query :
$stime = '06:00:00';
$result = $wpdb->get_var($wpdb->prepare("SELECT * FROM table WHERE start_hour='$stime'", ARRAY_A));
Upvotes: 1