我正在尝试仅显示过去30天内未更新的商家信息。
此查询工作正常,但显然缺少30天的更新要求:
$Listings = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."fsrep_listings, ".$wpdb->prefix."fsrep_listings_to_users WHERE ".$wpdb->prefix."fsrep_listings_to_users.ID = ".$Userprofile->ID." AND ".$wpdb->prefix."fsrep_listings.listing_visibility = 1 AND ".$wpdb->prefix."fsrep_listings.listing_id = ".$wpdb->prefix."fsrep_listings_to_users.listing_id");
我试过这个,但无济于事:
$Listings = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."fsrep_listings, ".$wpdb->prefix."fsrep_listings_to_users WHERE ".$wpdb->prefix."fsrep_listings_to_users.ID = ".$Userprofile->ID." AND ".$wpdb->prefix."fsrep_listings.listing_visibility = 1 AND ".$wpdb->prefix."fsrep_listings.listing_id = ".$wpdb->prefix."fsrep_listings_to_users.listing_id AND ".$wpdb->prefix."fsrep_listings.listing_last_updated < unix_timestamp(now() - interval 30 day");
如果您需要以下信息,我将使用以下时间戳格式将日期存储在数据库中:2011-02-12 22:23:01。我必须错过一些比较简单的东西。谢谢你的帮助!
答案 0 :(得分:0)
我想我明白了:
$Listings = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."fsrep_listings, ".$wpdb->prefix."fsrep_listings_to_users WHERE ".$wpdb->prefix."fsrep_listings_to_users.ID = ".$Userprofile->ID." AND ".$wpdb->prefix."fsrep_listings.listing_visibility = 1 AND ".$wpdb->prefix."fsrep_listings.listing_id = ".$wpdb->prefix."fsrep_listings_to_users.listing_id AND date_format(".$wpdb->prefix."fsrep_listings.listing_last_updated,'%Y%m%d')<date_format(adddate(now(),interval -30 day),'%Y%m%d')");