0
I am developing a dynamic input that checks whether the database contains a value if there is such value should not appear in the input, but I am experiencing 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 then when selecting the day 28/06/2016 the value of 00:00 should not be displayed, I already made the test of $_POST
and the value is coming correctly, I believe the error is inside While.
In the database, what is the type of the date field: DATE, DATETIME or VARCHAR?
– Ivan Ferrer
Good morning, the field is TEXT.
– Matheus Arruda
You want to list all the times and not show what’s in the bank, that’s it?
– Ivan Ferrer
This I want to list from 00:00 to 23:00, but if in the database has the value 01:00 I want the input to look like this 00:00 - 02:00 - 03:00 [...]
– Matheus Arruda
You are using "Hidden" would not be better not to print?
– Ivan Ferrer
Already tried Ivan, Hidden was the last attempt, the problem is that in the bank I have several values, today for example I have 4, in the first round the time loop is = 00:00 in the second is = 01:00 (At that moment appears the 00:00 and erases the 01:00. I need to create a logic that does not occur this problem.
– Matheus Arruda