Php Sql Query

Posted on 2016-10-13
Last Modified: 2016-10-13

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
Question by:pc-buddy
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
LVL 57

Expert Comment

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

Author Comment

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

LVL 57

Expert Comment

by:Julian Hansen
ID: 41842499
That's not a data record - can you post a script with the table definition and data.
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.


Author Comment

ID: 41842585

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
LVL 57

Accepted Solution

Julian Hansen earned 500 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.

Author Closing Comment

ID: 41842654
Thanks for all your help
LVL 57

Expert Comment

by:Julian Hansen
ID: 41842689
You are welcome.

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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