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
Solved

Mysqli Query

Posted on 2016-10-17
5
54 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 55

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 109

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 55

Expert Comment

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

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to count occurrences of each item in an array.
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.

792 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