Solved

Mysqli Query

Posted on 2016-10-17
5
40 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 51

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 108

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 51

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now