$result = $wpdb->get_results("SELECT * FROM wp_location_date WHERE location=$id ORDER BY location_date");
WordPress的function.php文件中的完整(ish)代码。
add_action('wp_ajax_nopriv_fetch_dates', 'get_location_date');
add_action('wp_ajax_fetch_dates', 'get_location_date');
function get_location_date() {
global $wpdb;
ob_clean();
$id = $_POST['id']; // Get the Request Id;
$result = $wpdb->get_results("SELECT * FROM wp_location_date WHERE location=$id ORDER BY location_date");
foreach ( $result as $value ) {
$option .= '<option value="'.$value->id.'">';
$option .= $value->date_coment;
$option .= '</option>';
}
echo '<option value="0" selected="selected">Select Date</option>'.$option;
提前感谢您的帮助。
答案 0 :(得分:1)
$result = $wpdb->get_results("SELECT * FROM wp_location_date WHERE location=$id and location_date >= curdate() ORDER BY location_date");
另外,请勿在SQL查询中使用原始用户输入!在字符串上使用mysql_real_escape_string,在整数上使用intval,例如
$id = intval($_POST['id']);
或
$result = $wpdb->get_results('SELECT * FROM wp_location_date WHERE location="'.mysql_real_escape_string($id).'" and location_date >= curdate() ORDER BY location_date');
答案 1 :(得分:1)
location_date的数据类型是什么? 你可以试试这个:
$result = $wpdb->get_results("SELECT * FROM wp_location_date WHERE location=$id AND location_date > current_date - 1 ORDER BY location_date");
有关MySQL Reference Guide的更多信息。