I'm developing a dynamic input that checks whether the database has a value if it does not appear in the input, but I'm having problems with my logic:
<?php
session_start();
require_once('library.php');
$hoje = date('d/m/Y');
$amanha = date("d/m/Y", mktime(0,0,0,date("m"),(date("d")+1),date("Y")));
$damanha = date("d/m/Y", mktime(0,0,0,date("m"),(date("d")+2),date("Y")));
$predata = $_POST['predata'];
//Realizo a consulta no banco de dados
$sql = "SELECT Hora FROM tbl_agenda WHERE Data = '$predata'";
//Atualizo algumas informações
$atualizahoje = "UPDATE tbl_agenda SET Data='". $hoje ."' WHERE id=33";
$atualizaamanha = "UPDATE tbl_agenda SET Data='". $amanha ."' WHERE id=34";
$atualizadamanha = "UPDATE tbl_agenda SET Data='". $damanha ."' WHERE id=35";
$qr1 = mysql_query($atualizahoje) or die(mysql_error());
$qr2 = mysql_query($atualizaamanha) or die(mysql_error());
$qr3 = mysql_query($atualizadamanha) or die(mysql_error());
$qr = mysql_query($sql) or die(mysql_error());
$ln1 = mysql_fetch_assoc($qr1);
$ln2 = mysql_fetch_assoc($qr2);
$ln3 = mysql_fetch_assoc($qr3);
echo '<option value="">Selecione..</option>';
// Realizo o while verificando os critérios e adicionando o select ao campo
while($ln = mysql_fetch_assoc($qr)){
if($ln['Hora'] != "00:00") {
echo '<option value="00:00">00:00</option>';
}
else {
echo '<option hidden value="00:00">00:00</option>';
}
if($ln['Hora'] != "01:00") {
echo '<option value="01:00">01:00</option>';
}
else {
echo '<option hidden value="01:00">01:00</option>';
}
if($ln['Hora'] != "02:00") {
echo '<option value="02:00">02:00</option>';
}
else {
echo '<option hidden value="02:00">02:00</option>';
}
if($ln['Hora'] != "03:00") {
echo '<option value="03:00">03:00</option>';
}
else {
echo '<option hidden value="03:00">03:00</option>';
}
if($ln['Hora'] != "04:00") {
echo '<option value="04:00">04:00</option>';
}
else {
echo '<option hidden value="04:00">04:00</option>';
}
if($ln['Hora'] != "05:00") {
echo '<option value="05:00">05:00</option>';
}
else {
echo '<option hidden value="05:00">05:00</option>';
}
if($ln['Hora'] != "06:00") {
echo '<option value="06:00">06:00</option>';
}
else {
echo '<option hidden value="06:00">06:00</option>';
}
if($ln['Hora'] != "07:00") {
echo '<option value="07:00">07:00</option>';
}
else {
echo '<option hidden value="07:00">07:00</option>';
}
if($ln['Hora'] != "08:00") {
echo '<option value="08:00">08:00</option>';
}
else {
echo '<option hidden value="08:00">08:00</option>';
}
if($ln['Hora'] != "09:00") {
echo '<option value="09:00">09:00</option>';
}
else {
echo '<option hidden value="09:00">09:00</option>';
}
if($ln['Hora'] != "10:00") {
echo '<option value="10:00">10:00</option>';
}
else {
echo '<option hidden value="10:00">10:00</option>';
}
In the database I have the record Data = 28/06/2016 e Hora = 00:00
, in my input so when selecting the 06/28/2016 the value of 00:00 should not be displayed, I already tested the $_POST
and the value is arriving correctly, I believe the error is within the While.