[英]How to parse value from wordpress $wpdb->get_results()?
I am working on wordpress theme and failed to use arithmatics operation on wpdb->get_results(). 我正在研究wordpress主题,但无法在wpdb-> get_results()上使用算术运算。
If i write simple, then it update sucessfully in database 如果我写的很简单,那么它将在数据库中成功更新
$sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";
$result = $wpdb->get_results($sql) or die(mysql_error());
$calc = $result;
But if I use minus operation with result it throws fatal error. 但是,如果我对结果使用减号运算,则会引发致命错误。
$sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";
$result = $wpdb->get_results($sql) or die(mysql_error());
$calc = $result - 1;
Error 错误
Fatal error: Unsupported operand types in C:\xampp\htdocs\beta\wp-content\themes\byt-child\includes\post_types\accommodations.php on line 1199
Freinds please suggest me how to resolve this. Freinds请建议我如何解决此问题。 I have used result->room_count -1 but stucked on result.
我使用了result-> room_count -1,但是卡在了结果上。
If you are expecting a single result field, you should use get_var 如果期望单个结果字段,则应使用get_var
$sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";
$result = $wpdb->get_var($sql);
if( $result ) {
$calc = $result - 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.