|
|
|
|
Bonjour à tous
J'ai un souci d'affichage de résultat issu d'une boucle sur un switch...
ma table1 est composée comme suit:
id_table day h1 h2
1 Mon 0 5
2 Mon 0 0
[code]
$date1 = Mon;
$hms=1;
$i =1;
$r = 3;
$array=array();
while ( $i < $r) {
$resultatfiche=mysql_query("select * from table1 where id_table like '".$i."' and day like '".$date1."'",$connexion_sql);
if (mysql_num_rows($resultatfiche) != 0){
$day=mysql_result($resultatfiche,0,"day");
$h1=mysql_result($resultatfiche,0,"h1");
$h2=mysql_result($resultatfiche,0,"h2");
switch ($date1)
{
case 'Mon':
if (($h1<$hms) and ($hms<($h2))
{
$var='2';}
else {
$var='1';}
break;
case 'Tue':
if (($h1<$hms) and ($hms<($h2))
{
$var='2';}
else {
$var='1';}
break;
etc...
case 'Sun':
if (($h1<$hms) and ($hms<($h2))
{
$var='2';}
else {
$var='1';}
break;
else {
$var='3';
}
$array[$i]="$var";
$i++;
}
$array=array_count_values($array);
print_r($tableau);
[/code]
Résultat...
Array ( [3] => 1 [2] => 1 [] => 1 )
alors que je cherche à avoir:
Array ( [3] => 1 [2] => 1 [1] => 1 )
Quelqu'un peut il m'aider?
Configuration: Mac OS X Safari 522.12.1
Bonjour,
if (mysql_num_rows($resultatfiche) != 0)
{
$day=mysql_result($resultatfiche,0,"day");
$h1=mysql_result($resultatfiche,0,"h1");
$h2=mysql_result($resultatfiche,0,"h2");
switch ($date1)
{
case 'Mon':
case 'Tue':
case 'Wed':
case 'Thu':
case 'Fri':
case 'Sat':
case 'Sun':
if ($h1<$hms && $hms<($h2))
{
$var='2';
}
else
{
$var='1';
}
break;
default:
$var='3';
break;
}
$array[$i]=$var;
$i++;
}
$array=array_count_values($array);
print_r($tableau);En espérant que cela aide...
Xavier |
Merci pour ta réponse je commence à voir le bout du tunnel surtout grâce au default!
|
Mmmmh, que dirais-tu de ceci alors ?
$resultatfiche = mysql_query("SELECT * FROM table1 WHERE id_table >= $i AND id_table < $r AND day = '$date1'", $connexion_sql);
$j = 0;
while ($data = mysql_fetch_assoc($resultatfiche))
{
$day = $data["day"];
$h1 = $data["h1"];
$h2 = $data["h2"];
switch ($date1)
{
case 'Mon':
case 'Tue':
case 'Wed':
case 'Thu':
case 'Fri':
case 'Sat':
case 'Sun':
if ($h1<$hms && $hms<($h2))
{
$var='2';
}
else
{
$var='1';
}
break;
default:
$var='3';
break;
}
$array[$j]=$var;
$j++;
}
$array=array_count_values($array);
print_r($tableau); |