mysql is not working with less then and greater then value

292
November 25, 2016, at 9:50 PM

I hav created sql query where I would like to get data that are greater then start time and less then end time means in between those time but the problem is that I am not getting any results in return can anyone help me out my time is in integer

$sql  = mysqli_query($connection, "SELECT * FROM listings WHERE address = '$address' AND start_time >= '$start_time' AND end_time <= '$end_time' LIMIT 1");
$data = mysqli_fetch_array($sql);

Here is data of db

address : 1351 Powell St
start_time : 900
end time : 1080

My inserted query is

SELECT * FROM listings 
WHERE address = '1351 Powell St' AND start_time >= '915' AND end_time <= '930' LIMIT 1

I do not know why it is returning 0 recods

Answer 1

Your query won't return any rows because doesn't match the criteria.

start_time >= '915' AND end_time <= '930'

Your end_time is 1080, greater than 930, so it won't return any value. The same with the start_time.

Answer 2

Per your posted data condition should be other way round like

SELECT * FROM listings 
WHERE address = '1351 Powell St' 
AND start_time <= '915' 
AND end_time >= '930' 
LIMIT 1

BTW, are those start_time and end_time time column is of type INT or VARCHAR? Cause if they are string type then I wonder how the >= comparison is going on.

Answer 3

If start_time and end_time are type of integers, then try this

SELECT * 
FROM listings 
WHERE address = '1351 Powell St' 
      AND start_time >= 915
      AND end_time <= 930
LIMIT 1;

Your end_time is 1080, greater than 930, so it won't return any value. Your start_time is 900, less than 915, so it won't return any value.

READ ALSO
Can&#39;t Export to Excel using Php7 and Mysql

Can't Export to Excel using Php7 and Mysql

I need to import mysql datas to an excel fileI'm using php7

270
CakePHP 3: HasOne relation throws SQLSTATE[23000]: 1048 Column &#39;id&#39; cannot be null

CakePHP 3: HasOne relation throws SQLSTATE[23000]: 1048 Column 'id' cannot be null

I've got a strange issue with CakePHP which I can't resolve after 2 hours of debugging

291
How to configure circle.yml in order to call the database ?

How to configure circle.yml in order to call the database ?

I am trying to configure the CircleCi setupWhen I try to run the tests in my own environment then everything works out, but when I try to run it in Circle CI, then I haave got this error

264
MySQL - conditional select in group

MySQL - conditional select in group

I have a simple table with several rows and I would like to group them by id_room and select value only when condition is trueProblem is that condition is always false even there is a row with right date column year_month

271