Solved

Mysqli Query

Posted on 2016-10-17
5
60 Views
Last Modified: 2016-10-26
Hi,

I have a column in my data base called end_date, there could be 2 data types in this column

2016-01-01

or it could be simply

0000-00-00

My query looks like this

"SELECT room_id FROM child_room WHERE child_id='".$id."' AND end_date > ".$today." Or end_date = '0000-00-00'"

Open in new window


There are multipul entris in the DB for each child so I need the current used row for that child.

The query fails.

Can you see whats wrong

Thanks
0
Comment
Question by:pc-buddy
5 Comments
 
LVL 56

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41847467
Boolean logic operators have precedence

A AND B OR C

Is the same as

(A AND B) OR C

In your case you want
A AND (B OR C)

Does this do what you want?
"SELECT room_id FROM child_room WHERE child_id='".$id."' AND (end_date > ".$today." Or end_date = '0000-00-00')"

Open in new window

1
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 41847479
You might also use WHERE end_date <> '0000-00-00' to eliminate the outliers.  Then you can use the ORDER BY and LIMIT clauses to get sensible results sets.

This would probably be syntactically correct (note quotes around $today).  You might add ORDER  BY and LIMIT clauses.
"SELECT room_id FROM child_room WHERE child_id='$id' AND end_date <> '0000-00-00' AND end_date > '$today' "

Open in new window

1
 
LVL 9

Assisted Solution

by:Brian Tao
Brian Tao earned 125 total points
ID: 41847864
You forgot to enclose $today in single quotes.
1
 

Author Closing Comment

by:pc-buddy
ID: 41861451
Thanks all, helped a lot
0
 
LVL 56

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Make login page safer 3 32
MySQL stored procedure returning null values 4 27
php output utf-8 problem 6 24
Can I use php variable in jquery 8 22
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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