I'm trying to make an online searchable database. I want the user to be able to search for all entries by year, so if they want a specific year, there is a search box for that. If they want to input a range of years, I put two search boxes for that, which map to the variables "startyear" and "endyear." Here is my code in my php file:
<?php
$year=$_GET['year'];
$startyear=$_GET['startyear'];
$endyear=$_GET['endyear'];
$result = mysql_query(" SELECT * FROM DATABASE WHERE year(date_on_ledger) LIKE '%$year%' AND year(date_on_ledger) BETWEEN '%$startyear%' AND '%$endyear%' ");
This doesn't work, when I try putting in a start and end year, it gives me no results. I think it's because of the AND (it's trying to find years between start and endyear, that also match the normal year entry being empty). How should I go about fixing this so I can have both search options? Thanks!