Issue with data array format

时间:2014-07-14 作者:Sanjay Nakate

我正试图从表中获取日期记录booking_history 使用以下代码,但结果数组不显示start_date 柱当我回显查询时,查询将准确显示值。

$booking_date = $_POST[\'booking_date\'];

$post_id = $_POST[\'post_id\'];

echo $check_cust_query = "SELECT start_date FROM `".$wpdb->prefix."booking_history`
                        WHERE start_date=\'".$booking_date."\'
                        AND post_id=\'".$post_id."\'";

                 $results_check_cust = $wpdb->get_results ($check_cust_query);
                print_r ($results_check_cust);
                foreach ( $results_check_cust as $key => $value )
                    { 
                      $date= $value->start_date;
                      echo  $date;
                    } 
波纹管为台面结构table

1 个回复
最合适的回答,由SO网友:Shazzad 整理而成

不过,您的代码看起来不错。但请尝试以下方法-

$current_date = $_POST[\'current_date\'];
$current_date = date( \'Y-m-d\', strtotime($current_date) );

$post_id = (int) $_POST[\'post_id\'];

$query = $wpdb->prepare( "SELECT start_date FROM {$wpdb->prefix}booking_history WHERE start_date=%s AND post_id=%d", $current_date, $post_id );
/* get_col used to retrieve column records */
$results = $wpdb->get_col( $query );

echo \'<pre>\'; print_r( $results ); echo \'</pre>\';

结束

相关推荐

Accessing two databases

我的服务器上有两个数据库,我想知道有没有办法从wordpress访问这两个数据库?我的想法是将第二组凭据添加到wp-config.php.