IndianaGuy Posted November 19, 2017 Share Posted November 19, 2017 I am getting incorrect results with this (getting future events in the results). I am not sure if it is a date issue, or the select statement is bad. I am trying to select all the rows that have $ses_memberID in any of those columns and at the same time, only display the rows that will be on the correct date. The table structure for pp_date is the standard Date type which i believe is Y-m-d format. My next step will be to find out which column is found the search criteria in. Just in case that will effect how this step will look. Thank you so much for your help! $todaysDate=date("Y-m-d"); echo $todatsDate; // testing and the output is 2017-11-19 $sqlMC = "SELECT * FROM tbl_pp WHERE Col1 Or Col2 Or Col3 OR Col4 OrCol5 Or Col6 = '$ses_memberID' AND pp_date = '$todaysDate'"; $resultMC = mysqli_query($conn, $sqlMC); if (mysqli_num_rows($resultMC) > 0) { while($rowMC = mysqli_fetch_array($resultMC)) { //printing the rows } } else { echo "none found"; } //OUTPUT IS : I get 2017-11-19 rows printed and also 2017-11-20 showing as well!! Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2017 Share Posted November 20, 2017 That list of ORs isn't going to do anything (or, more specifically, it's going to return every row where any of those 5 columns are not empty). If you want to test if a certain value is in multiple columns you need to spell it out: Col1 = '$ses_memberID' OR Col2 = '$ses_memberID' OR ... You should also use parentheses to group the OR and AND operators to be explicit about what you're telling it to do. Lastly, you should use prepared statements whenever you need to put data in a query. Link to comment Share on other sites More sharing options...
IndianaGuy Posted November 20, 2017 Author Share Posted November 20, 2017 Thank you sir. I have ran into a couple of prepared statements examples but I have been shy to learn them. This is a good time to just get it done. I appreciate you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now