Solved

Mysqli Query

Posted on 2016-10-17
5
47 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 52

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 52

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

13 Experts available now in Live!

Get 1:1 Help Now