Jump to content

Query to search column for date - PHP


xxclear

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/276741-query-to-search-column-for-date-php/
Share on other sites

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.

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.