问题
My code is correct (I've been programming for 13 years), but for some reason when I use a variable in a SELECT query in the WHERE clause, I get no result. If I hardcode it, it works. How could this be? Blowing my mind...
$track = $wpdb->get_row($wpdb->prepare("SELECT tracking_id, order_id, outbound_tracking_number, return_tracking_numbers FROM wp_woocommerce_trackingnumbers WHERE order_id = %s", $o_id));
Thanks!
回答1:
I think it should be (%s
should be %d
)
$track = $wpdb->get_row($wpdb->prepare("SELECT tracking_id, order_id, outbound_tracking_number, return_tracking_numbers FROM wp_woocommerce_trackingnumbers WHERE order_id = %d", $o_id));
%s
for strings and %d
for digits and variable $o_id
sounds like an integer to me.
来源:https://stackoverflow.com/questions/17004556/wordpress-wpdb-get-row-query-wont-work-with-variable-but-works-with-hardco