I have an SQL database for photos and videos(well, their file locations), and I'm trying to let users see day by day results, but as not every day has entries, some combinations of dates return blank pages. How could you ensure the users only see days where records exist (and yes, I'm sure I'm looking at this the wrong way)?
At the moment I have three hardcoded drop downs that I combine to then compare with the timestamp, but there's no checking, so if I chose 2021, I could then select December. Or if I selected November, I could select 26. It should be something like this:
IF YEAR = 2021 THEN MONTH = 1-11;
IF MONTH = 2 THEN DAY = 1,4,5,7;
THEN $date_value = 2021-2-4
<form method=post name=f1 action=''><input type=hidden name=todo value=submit>
<table border="0" cellspacing="0" >
<tr><td align=left >
<select name=year value=''>Select Year</option>
<option value='2021'>2021</option>
<option value='2020'>2020</option>
<option value='2019'>2019</option>
<option value='2018'>2018</option>
<option value='2017'>2017</option>
</select>
<input type=submit value=Submit>
</table>
</form>
(There's also a month and day list, but ignoring hours/seconds.)
$todo=$_POST['todo'];
if(isset($todo) and $todo=="submit"){
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
$date_value="$year-$month-$day";
echo "<h1>$date_value</h1><br>";
}
And that date variable gets past to the SQL query.
$result = $conn->prepare("SELECT * FROM database WHERE date(datetime) LIKE '$date_value%' ORDER BY datetime");
Aucun commentaire:
Enregistrer un commentaire