Solved

Mysqli Query

Posted on 2016-10-17
5
70 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
[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
5 Comments
 
LVL 57

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 57

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…
The viewer will learn how to count occurrences of each item in an array.

717 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