xxclear Posted April 9, 2013 Share Posted April 9, 2013 How do I search a column for a date which is stored as a var? Is this the best way? $result = mysqli_query($link, " SELECT id, col1, col2, datum, col4, col5, col6, col7, col8, col9 FROM table WHERE `datum` = '$datum' " ) OR die(mysqli_error($link)); Thanks in advance. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 9, 2013 Share Posted April 9, 2013 that should find exact date matches. if it didn't, you would need to troubleshoot why. the first step should be to form your sql query statement in a variable so that you can echo it to see exactly what the query statement is. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Author Share Posted April 9, 2013 Would echoing $result have the same affect? Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Author Share Posted April 9, 2013 ok so i have set the query to a variable and used : print_r($result_debug); I get echoed back: "mysqli_result Object ( )" Where do i go from here, because your right: $result = mysqli_query($link, " SELECT id, col1, col2, datum, col4, col5, col6, col7, col8, col9FROM table WHERE `datum` = '$datum' " ) OR die(mysqli_error($link)); Doesn't work, and its killing me. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 9, 2013 Share Posted April 9, 2013 $query = "SELECT id, col1, col2, datum, col4, col5, col6, col7, col8, col9 FROM table WHERE `datum` = '$datum'"; // form the query statement in a variable echo $query; // echo the query statement Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) Thanks for replying. So this is what i did: $query = " SELECT id, auditor, auditee, datum, department, func, proc, audit_type, copy_to, comments FROM audit_data WHERE `auditor` LIKE '%$search_field%' OR `auditee` LIKE '%$search_field%' OR `department` LIKE '%$search_field%' OR `func` LIKE '%$search_field%' OR `proc` LIKE '%$search_field%' OR `audit_type` LIKE '%$search_field%' OR `id` = '$radio_id' OR `datum` = '$datum' " $result = mysqli_query($link, $query ) OR die(mysqli_error($link)); got a parse error on $result = mysqli_query($link, $query ) This is the real code i need it to work on btw, if it helps. What have a i done wrong? Edited April 9, 2013 by xxclear Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 9, 2013 Share Posted April 9, 2013 you are missing the ; on the end of the string assignment statement. Quote Link to comment Share on other sites More sharing options...
xxclear Posted April 9, 2013 Author Share Posted April 9, 2013 Typical, i got it to work just as i was getting a print out for here. It seems that if i put in a date with a garbage keyword it gets the row with the date but if i don't put in a keyword it ignores the date... i thought the OR operator was supposed to overcome that? "The OR operator displays a record if either the first condition or the second condition is true." as taken from W3C Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.