xxclear Posted April 9, 2013 Share Posted April 9, 2013 Ok, so i am trying to compare a date stored as a variable against a row in mysql, this is where i am so far: I need to be able to search the table for: 1) a search keyword 2) a combination of a date, for example (just 2013) or (march-2012) or (7th of june) or (5th of september 2012) or (just the 16th) etc... $result = mysqli_query($link, " 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') " ) OR die(mysqli_error($link)); Its only a small table otherwise I would be indexing. The variable and row are both stored in native format (YYYY-MM-DD) (If i put in a keyword into my $search_field it displays all the rows with a match, that works a treat). The above example shows an exact match between the row and var which as it happen doesnt work. I have a calender setup on the input form and search form that will put in any date like this 2013-04-08 or 2013-00-08 etc. Logically this is what i want (unfortunately doesn't work): if day($datum) = "00" {day($datum) = ""} else { day($datum) = day($_REQUEST['date1'] } if month($datum) = "00" {month($datum) = ""} else { month($datum) = month($_REQUEST['date1'] } if year($datum) = "0000" {year($datum) = ""} else { year($datum) = year($_REQUEST['date1'] } // select select * from audit_data where `datum` = if(isset(day($datum))){day($datum)} OR if(isset(month($datum))){month($datum)} OR if(isset(year($datum))){year($datum)} OR OR [search keyword code here] date1 being the calender output... If the above seem odd, or simply wrong, forgive me, im just trying to get the point across as clear as i can. Can anybody give me a head start on how to do this, any advice, links, examples, structure will be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/276715-compare-date-against-row-in-mysql/ Share on other sites More sharing options...
xxclear Posted April 9, 2013 Author Share Posted April 9, 2013 Don't shy away chap & chapettes, any advice will be appreciated. Link to comment https://forums.phpfreaks.com/topic/276715-compare-date-against-row-in-mysql/#findComment-1423697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.