Solved

Php Sql Query

Posted on 2016-10-13
7
26 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
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

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

Author Comment

by:pc-buddy
Comment Utility
start_date is 2016-09-02
end_date is 2016-12-15

Thanks
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
That's not a data record - can you post a script with the table definition and data.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:pc-buddy
Comment Utility
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 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
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
Comment Utility
Thanks for all your help
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now