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
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.

Link to comment
Share on other sites

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 by xxclear
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.