?
Solved

Php Sql Query

Posted on 2016-10-13
7
Medium Priority
?
62 Views
Last Modified: 2016-10-13
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
Comment
Question by:pc-buddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41842447
Try quoting your dates - otherwise what does your data look like?
0
 

Author Comment

by:pc-buddy
ID: 41842451
start_date is 2016-09-02
end_date is 2016-12-15

Thanks
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41842499
That's not a data record - can you post a script with the table definition and data.
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

Author Comment

by:pc-buddy
ID: 41842585
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
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41842645
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
 

Author Closing Comment

by:pc-buddy
ID: 41842654
Thanks for all your help
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41842689
You are welcome.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question