0
I’m trying to compare the dates that come from a database array to be able to organize them within a timeline. The problem is that I can’t compare the dates to know where to place each entry...
Maybe the problem is that within the array the dates are in date format, but if so, how to compare?
Follows the code:
<tbody>
<tr>
<td><center>Manhã</center></td>
<?php
foreach($periodo as $data){
while ($arrayBancas = mysql_fetch_array($oBanca->retorno())){
if ($arrayBancas['data'] == $data->format("Y-m-d")){
echo '<td>teste</td>';
}
}
}
?>
</tr>
Content of variables:
(Period)
if(!isset($_SESSION)) {session_start();}
$idSemestre = $_SESSION['SemestreGeral'];
$oSemestre = new semestresclass();
$oSemestre -> listarEdicao($idSemestre);
$array = mysql_fetch_array($oSemestre->retorno());
$start_date = $array['DataDeInicio'];
$end_date = $array['DataDeTermino'];
$inicio = new DateTime($start_date);
$fim = new DateTime($end_date);
$fim->modify('+1 day');
$interval = new DateInterval('P1D');
$periodo = new DatePeriod($inicio, $interval ,$fim);
(Array of Benches)
if(!isset($_SESSION)) {session_start();}
$idSemestre = $_SESSION['SemestreGeral'];
$oBanca = new bancasclass();
$oBanca -> listar ($idSemestre);
$arrayBancas = mysql_fetch_array($oBanca->retorno())
Follows the var_export value of the variables:
arrayBancas: array ( 0 => '1', 'idB' => '1', 1 => NULL, 'data' => NULL, 2 => NULL, 'time' => NULL, 3 => '316', 'room' => '316', )
date: Datetime::__set_state(array( 'date' => '2014-06-10 00:00:00', 'timezone_type' => 3, 'Timezone' => 'GMT', ))
You need to organize them as?
– Marcio Mazzucato
For days and shifts. In this case, inside this $arrayBancas there I have 'entries of a schedule' with time, date and place... then I’ll probably have to compare the time of each entry with which turn it fits and then play on the screen...
– Alceu
Try to better organize your query for data to come in a format that facilitates logic
– Marcio Mazzucato
Look if it helps you http://answall.com/questions/39631/howto compare a-frase-insertedwith as-existentes-na-bd-devolvendo-a-probabilid/39639#39639
– vmontanheiro
No, it wasn’t that... I needed to compare date with string... How could I do?
– Alceu
In the database the date is stored as string? Or this as date?
– Rogerio Coelho
In the bank she’s like Date
– Alceu
it’s strange that this
if ($arrayBancas['data'] == strtotime('2014-06-05')){ echo '<td>teste</td>';}
also doesn’t work...– Alceu
Post the contents of $period and $arrayBancas using var_export().
– Bruno Augusto
I added the codes of each of them there in the question to be better understood
– Alceu
This doesn’t help because having the variables without having what they represent makes it impossible for any test to be done. By code we can even do a mental reverse engineering and we know that $array has two indices called Datadeinicio and Datadetermino. But so what? If, for example, we need to know the size of the arrays to figure out a solution we would not have as it may be only these two as can be more. I repeat, do a var_export() of the variables $array and $arrayBancas and edit the question again.
– Bruno Augusto
Now I understand! I did not know this function, very good! I put the values there, by q da to see the date is null, this may be preventing comparison right?
– Alceu
But the strange thing is that if I go through the array giving an echo in the array at the date position it prints the dates right... And now?
– Alceu
Great. I imagine this $arrayBancas should not return this much of null value, so you need to fix your query so that it returns workable data. In the meantime, you should also do a var_dump() to see if $array, $beginning, $end and $period and see if the objects are being filled with what is expected. Fixed this you can use the answer I will leave below.
– Bruno Augusto