Solved

Php Sql Query

Posted on 2016-10-13
7
42 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 55

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 55

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 55

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 55

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Stored Proc - Performance Enhancement 15 55
XML extra information 8 29
Sum particular field in database 2 16
IIF in access query 19 26
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
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 count occurrences of each item in an array.

828 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