Query works in phpmyadmin, but does not work in PHP

0

I'm trying to make a query via php in Mysql, but it's not working in PHP, but it works in PHPMYADMIN.

$check_in = strtotime($arrival);
$check_out = strtotime($departure);

Queries I've tried in PHP ...

$query = "SELECT * FROM wp_st_availability WHERE post_id = 5993 AND check_in > '$check_in' and check_in < '$check_out'";

$query = "SELECT * FROM wp_st_availability WHERE post_id = '5993' AND check_in > '$check_in' and check_in < '$check_out'";

$query = "SELECT * FROM wp_st_availability WHERE post_id = '5993' AND check_in > '" . $check_in . "' and check_in < '" . $check_out . "'

;

Full code:          $ query="SELECT * FROM wp_st_availability WHERE post_id = '$ post_id' AND check_in> '". $ check_in. "'and check_in

asked by anonymous 15.02.2018 / 17:26

1 answer

0

Look, I did like this:

In the bank:

Inthephpcode:

<?php$mysqli=newmysqli("host", "user", "password", "db");

$id_post = 1;

$check_in = strtotime('2018-02-12') ;
$check_out = strtotime('2018-02-15');

//$check_in =1518393600;
//$check_out = 1518652800;

if($sth = $mysqli->query("SELECT * FROM teste WHERE id='$id_post' AND 
check_in > '$check_in' AND check_in < '$check_out'")){
    while ($row = $sth->fetch_assoc()) {
       echo $row['nome'];
    }
}

response:

Note that in the database the check_in value is 1518393700, the value of the $ check_in variable is smaller than it, and check_in is less than the $ check_out, that is, between the two, review your check_in values in your table, perhaps this is the problem, to be sure of the values you searched for, you can do a var_dump ($ variable); to see if variable is going right

    
15.02.2018 / 17:55