Solved

Php Sql Query

Posted on 2016-10-13
7
47 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 56

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 56

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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 56

Accepted Solution

by:
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.
0
 

Author Closing Comment

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

Expert Comment

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.
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 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 …

730 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