V
V
ValeraValera2017-07-21 13:39:28
PHP
ValeraValera, 2017-07-21 13:39:28

How to insert php variables into SQL query?

variable
$nowDate = current_time('Ymd', 0);
returns // 2017-07-21
how to insert $nowDate into query for date place 2017-07-20 to make it work

$userLists = $wpdb->get_results( 'SELECT user_name, user_bet, user_time FROM wp_konkurs WHERE `user_time` BETWEEN "2017-07-20 00:00:00" AND "2017-07-20 23:59:59"  ORDER BY user_time DESC ');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shapoval, 2017-07-21
@cluberr

For variables to work, they must either be written without quotes or in double quotes.

$a = 5;
echo $a; # 5
echo "$a"; # 5
echo '$a'; # $a

In your case, you need to write ' instead of 2017-07-20. $nowDate . '
$userLists = $wpdb->get_results("SELECT `user_name`, `user_bet`, `user_time` FROM `wp_konkurs` WHERE `user_time` BETWEEN '$nowDate 00:00:00' AND '$nowDate 23:59:59' ORDER BY `user_time` DESC");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question