[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79
  • Last Modified:

Php Sql Query

Hi,

I'm trying to pull all records for a certain Id from the Db, this is my query

SELECT * FROM child_session WHERE child_id=293 And end_date > 2016-10-13 And start_date < 2016-10-13

Open in new window


But no results are returned.

What is wrong please

Thank Simon
0
pc-buddy
Asked:
pc-buddy
  • 4
  • 3
1 Solution
 
Julian HansenCommented:
Try quoting your dates - otherwise what does your data look like?
0
 
pc-buddyAuthor Commented:
start_date is 2016-09-02
end_date is 2016-12-15

Thanks
0
 
Julian HansenCommented:
That's not a data record - can you post a script with the table definition and data.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pc-buddyAuthor Commented:
Hi,

Sorry, picture attached of DB,

I need to pull only session that are active and I've noticed the end dates of some are 0000-00-00

$sessionsq = "SELECT * FROM child_session WHERE child_id='".$id."' And end_date > '".$today."' And start_date < '".$today."'";	
$childsessions = mysql_query( $sessionsq, $conn );[embed=file 1122094]

Open in new window


Thanks Simon
query.jpg
0
 
Julian HansenCommented:
Except that data doesn't match the query you posted in the beginning - there is no child_id 293 and none of the dates are going to match the criteria of the where.
None of the end_dates are > today.

To say why your query is not working - need the same data you are working with

For instance if I run this query against the data you posted
SELECT * FROM child_session WHERE child_id=1 AND end_date > '2016-09-13' AND start_date < '2016-10-13'

Open in new window

I get 1 row returned as expected.

BTW: you are using the mysql library which has been deprecated - you should consider moving off that to mysqli.
0
 
pc-buddyAuthor Commented:
Thanks for all your help
0
 
Julian HansenCommented:
You are welcome.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now