IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Problème d'affichage de requete en boucle


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Janvier 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 13
    Par défaut Problème d'affichage de requete en boucle
    Bonjour,
    Je fais une boucle pour afficher toutes les réservations de toutes les salles du planing du jour. mais cela ne focntionne pas...!
    quelqu'un pourrait-il m'aider ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    <?
    /* Is it a public day? */
    $qry =  "SELECT IdHd, YearHd FROM ".HOLI." ".
    		"WHERE DayHd = '".$curday."' ".
    		"AND MonthHd = '".$curmonth."' ";
    $ret = mysql_query($qry, $cnx) ;
    $hd = mysql_fetch_row($ret) ;
    if ( $hd[0]!=0 && ($hd[1]==NULL || $hd[1]==$curyear) ) $holiday = $txt[8];		
     
    /* Requête pour afficher tous les ateliers */
    $req = "select IdRm, NameRm, BkcolRm, FtcolRm FROM rp_room ORDER BY IdRm";
    if (!$res = mysql_query($req)) exit("Erreur : ".mysql_error());
    while ($col = mysql_fetch_row($res))
     
    /* Room name and date (mise en commentaire pour infos)*/ 
    /* $qry = "SELECT IdRm, NameRm, BkcolRm, FtcolRm FROM ".ROOM; */
    /* $ret = mysql_query($qry, $cnx) ; */
    /* while($col = mysql_fetch_row($ret))*/ 
    { 
        $idroom = $col[0]; 
        $nameroom = $col[1]; 
        $bkcolorroom = $col[2]; 
        $ftcolorroom = $col[3]; 
     
    echo'<TH COLSPAN="3" WIDTH="100%" VALIGN="TOP" BGCOLOR="'.$bkcolorroom.'">'
       .'<P><FONT FACE="'.$font.'" COLOR="'.$ftcolorroom.'">'
       .$nameroom.' - '.sprintf('%02d', $curday).'/'
       .sprintf('%02d', $curmonth).'/'.$curyear.'<BR>'.$holiday.'</P></TH>';
     
     
    } 
    ?> 
     
    		</TR>
    	</THEAD>
    	<TBODY>
    <?
    /* Requête pour extraire toutes les réservations */
    $qry = "select IdRs, TitleRs, BegRs, EndRs FROM rp_resa ORDER BY BegRs";
    if (!$res = mysql_query($qry)) exit("Erreur : ".mysql_error());
    while ($col = mysql_fetch_row($res))
     
    /* Extract reservation (code original)*/
    /* $qry =  "SELECT IdRs, TitleRs, BegRs, EndRs ". */
    /*		"FROM ".RESA." ". */
    /*		"WHERE IdRm = ".$idroom." ". */
    /*		"AND DateRs = '".$curyear."-".$curmonth."-".$curday."' ". */
    /*		"ORDER BY BegRs"; */
     
    $ret = mysql_query($qry, $cnx) ; 
     
    $c=0;
     
    while ( $col = mysql_fetch_row($ret) )
    {
    	$idresa[$c] = $col[0] ;
    	$titleresa[$c] = $col[1] ;
    	// extract and formate begin time from 07:00 to 0730
    	$begh = substr($col[2],0,2);
    	if (intval(substr($col[2],3,2))==30) $begm="30"; else $begm="00";
    	$begresa[$c] = $begh.$begm;
    	// extract and formate end time from 07:00 to 0730
    	$endh = substr($col[3],0,2);
    	if (intval(substr($col[3],3,2))==30) $endm="30"; else $endm="00";
    	// Formula to calculate number of boxes to set
    	$begtmp = intval($begh.$begm);
    	$endtmp = intval($endh.$endm);
    	$ecart  = ($endtmp - $begtmp)/100;
    	$intpart = intval($ecart);
    	$decpart = ($ecart - $intpart)*10;
    	$boxresa[$c] = $intpart *2-1; # <------- Modify in 1.4
    	if ( $decpart!=0 ) $boxresa[$c]++; 
    	$c++;
    }
     
    $c = 0; $odd=1;
     
    for ( $t=$begrange ; $t<$endrange ; $t++)
    {
    	$view = sprintf ( $viewbutton, $idresa[$c]);
    Merci par avance.

  2. #2
    Rédacteur

    Avatar de Yoteco
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    1 099
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 099
    Par défaut
    Corrige déjà ta syntaxe, tes boucles while ne sont pas correctes, il manque des accolades. Ensuite donne nous l'erreur que PHP te retourne.
    Blog - Mon espace developpez -
    Oracle Certified Professional, Java SE 6 Programmer
    eZ Publish Certified developer

  3. #3
    Membre averti
    Inscrit en
    Janvier 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 13
    Par défaut ERREUR
    il affiche une seule colonne sans prendre en compte la date du jour.
    Ex : il reprend toutes mles réservation depuis le début. Sans prendre en compte la date du jour.

  4. #4
    Membre averti
    Inscrit en
    Janvier 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 13
    Par défaut LIMITER LES EXTRACTION
    Je viens de corriger mon code (enfin je crois) la question est de savoir comment je peux faire pour limiter les extractions des réservations à la date du jour. et deuxièment comment faire pour que une colonne s'affiche pour chaque salle. (affichage actuellement d'une seule colonne)

    voici le code modifié
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    <?
    /* Requête pour extraire toutes les réservations */
    $qry = "select IdRs, TitleRs, BegRs, EndRs FROM rp_resa ORDER BY BegRs";
    if (!$res = mysql_query($qry)) exit("Erreur : ".mysql_error());
    while ($col = mysql_fetch_row($res))
    {
    /* Extract reservation (code original)*/
    /* $qry =  "SELECT IdRs, TitleRs, BegRs, EndRs ". */
    /*		"FROM ".RESA." ". */
    /*		"WHERE IdRm = ".$idroom." ". */
    /*		"AND DateRs = '".$curyear."-".$curmonth."-".$curday."' ". */
    /*		"ORDER BY BegRs"; */
     
    $ret = mysql_query($qry, $cnx) ; 
     
    $c=0;
    }
    while ( $col = mysql_fetch_row($ret) )
    {
    	$idresa[$c] = $col[0] ;
    	$titleresa[$c] = $col[1] ;
    	// extract and formate begin time from 07:00 to 0730
    	$begh = substr($col[2],0,2);
    	if (intval(substr($col[2],3,2))==30) $begm="30"; else $begm="00";
    	$begresa[$c] = $begh.$begm;
    	// extract and formate end time from 07:00 to 0730
    	$endh = substr($col[3],0,2);
    	if (intval(substr($col[3],3,2))==30) $endm="30"; else $endm="00";
    	// Formula to calculate number of boxes to set
    	$begtmp = intval($begh.$begm);
    	$endtmp = intval($endh.$endm);
    	$ecart  = ($endtmp - $begtmp)/100;
    	$intpart = intval($ecart);
    	$decpart = ($ecart - $intpart)*10;
    	$boxresa[$c] = $intpart *2-1; # <------- Modify in 1.4
    	if ( $decpart!=0 ) $boxresa[$c]++; 
    	$c++;
    }
     
    $c = 0; $odd=1;
     
    for ( $t=$begrange ; $t<$endrange ; $t++)
    {
    	$view = sprintf ( $viewbutton, $idresa[$c]);
     
    	/* Full hour */
    	$curtime = $t *100 ;
    	$num="<BIG>".$t.":00</BIG>"; 
    	if ( $begresa[$c]==strval($curtime) ) {
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font, $titleresa [$c], $view); 
    		$nextline = 1 ; 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	elseif ( $nextline && $boxresa[$c]!=0 ) {
    		$boxresa[$c]--;
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font,"&nbsp;","&nbsp;"); 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	else printf ($lineNO, $num, $bkcolorroom, $ftcolorroom,
    			$style ['notreserved'], $font, $t, "00");
     
    	$view = sprintf ( $viewbutton, $idresa[$c]);
     
    	/* Half hour */
    	$curtime = $curtime+30;
    	$num="<SMALL>".$t.":30</SMALL>"; 
    	if ( $begresa[$c]==strval($curtime) ) {
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font, $titleresa [$c], $view); 
    		$nextline = 1 ; 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	elseif ( $nextline && $boxresa[$c]!=0 ) {
    		$boxresa[$c]--;
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom, 
    			$style ['reserved'.$odd], $font, "&nbsp;", "&nbsp;"); 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	else printf ($lineNO, $num, $bkcolorroom, $ftcolorroom,
    			$style ['notreserved'], $font, $t, "30");
    }
     
    ?>

  5. #5
    Membre averti
    Inscrit en
    Janvier 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 13
    Par défaut Affichage d'une boucle dans un tableau
    Bonjour,
    j'ai fait un site pour réserver des plages horaires.
    L'affichage par salle des réservations du jour fonctionne, je tente de faire une boucle pour afficher dans un tableau toutes les salles et toutes les réservation du jour. J'arrive à afficher toutes les salles mais je n'arrive pas à récupérer les réservations du jour pour chaque salle.
    Voici le code que j'ai fait.
    Merci d'avance de m'aider ce projet doit être bouclé pour la fin du mois et je bloque sur cette fonction. Merci si possible de me donner le code rectificatif.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    <?	
     
    /* Init variables */
    $resabutton = "";
    $holiday	= "";
    $idresa		= array_fill (0,48,0);
    $begresa	= array_fill (0,48,0);
    $nextline	= 0;
    $begrange 	= 7;  /* hour begin range to */
    $endrange 	= 20; /* end for daily planning  */
     
    /* Right date format */
    $curtime = sprintf("%02d",$curday)."-".sprintf("%02d",$curmonth)."-".$curyear;
     
    /* Right to make a reservation */
    if ( $resark==1 ) {
    $resabutton = "<A HREF=\"javascript:Popup('resanew.php?idroom=".
    			$idroom."&seek=".$curtime.
    			"&begh=%6\$s&begm=%7\$s',450,500,'resanew');\"><IMG ".
    			"SRC='images/resanew.gif' BORDER=0 ".
    			"TITLE='".$txt[9]."'></A>"; 
    }
     
    $viewbutton = "<CENTER><A HREF=\"javascript:Popup('resaopen.php?idresa=".
    			"%1\$s',450,500,'resaopen');\"><IMG SRC='images/view.gif' ".
    			"BORDER=0 TITLE='".$txt[30]."'></A>";
     
     
    $lineOK = "<TR>
    		<TD WIDTH=5%% VALIGN=TOP BGCOLOR=\"%2\$s\">
    			<FONT FACE=\"%5\$s\" COLOR=\"%3\$s\" SIZE=2>%1\$s
    		</TD>
    		<TD WIDTH=90%% BGCOLOR=\"%4\$s\">
    			<P><FONT FACE=\"%5\$s\" SIZE=2>%6\$s
    		</TD>
    		<TD WIDTH=5%% VALIGN=TOP>
    			<P>%7\$s</P>".
    		"</TD></TR>";
     
    $lineNO = "<TR>
    		<TD WIDTH=5%% VALIGN=TOP BGCOLOR=\"%2\$s\">
    			<FONT FACE=\"%5\$s\" COLOR=\"%3\$s\" SIZE=2>%1\$s
    		</TD>
    		<TD WIDTH=90%% BGCOLOR=\"%4\$s\">
    			<P ALIGN=CENTER>$resabutton &nbsp;</P>
    		</TD>
    		<TD WIDTH=5%% VALIGN=TOP>
    			<P>&nbsp;</P>".
    		"</TD></TR>";
    ?>
     
    <TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=3>
    	<THEAD>
    		<TR>
    <?
    /* Is it a public day? */
    $qry =  "SELECT IdHd, YearHd FROM ".HOLI." ".
    		"WHERE DayHd = '".$curday."' ".
    		"AND MonthHd = '".$curmonth."' ";
    $ret = mysql_query($qry, $cnx) ;
    $hd = mysql_fetch_row($ret) ;
    if ( $hd[0]!=0 && ($hd[1]==NULL || $hd[1]==$curyear) ) $holiday = $txt[8];		
     
    /* Requête pour afficher tous les ateliers */
    $req = "select IdRm, NameRm, BkcolRm, FtcolRm FROM rp_room ORDER BY IdRm";
    if (!$res = mysql_query($req)) exit("Erreur : ".mysql_error());
    while ($col = mysql_fetch_row($res))
     
    /* Room name and date (mise en commentaire pour infos)*/ 
    /* $qry = "SELECT IdRm, NameRm, BkcolRm, FtcolRm FROM ".ROOM; */
    /* $ret = mysql_query($qry, $cnx) ; */
    /* while($col = mysql_fetch_row($ret))*/ 
    { 
        $idroom = $col[0]; 
        $nameroom = $col[1]; 
        $bkcolorroom = $col[2]; 
        $ftcolorroom = $col[3]; 
     
    echo'<TH COLSPAN="3" WIDTH="100%" VALIGN="TOP" BGCOLOR="'.$bkcolorroom.'">'
       .'<P><FONT FACE="'.$font.'" COLOR="'.$ftcolorroom.'">'
       .$nameroom.' - '.sprintf('%02d', $curday).'/'
       .sprintf('%02d', $curmonth).'/'.$curyear.'<BR>'.$holiday.'</P></TH>';
     
     
    } 
    ?> 
     
    		</TR>
    	</THEAD>
    	<TBODY>
    <?
    /* Requête pour extraire toutes les réservations */
    /* $qry = "select IdRs, TitleRs, BegRs, EndRs FROM rp_resa ORDER BY BegRs"; */
    /* if (!$res = mysql_query($qry)) exit("Erreur : ".mysql_error()); */
    /* while ($col = mysql_fetch_row($res)) */
    /* { */
    /* Extract reservation (code original)*/
     
    $qry = "select IdRs, TitleRs, BegRs, EndRs FROM rp_resa ORDER BY BegRs";
     
    if (!$ret = mysql_query($qry, $cnx)) exit("Erreur : ".mysql_error()); 
     
    $c=0;
     
    while ( $col = mysql_fetch_row($ret) )
    {
    	$idresa[$c] = $col[0] ;
    	$titleresa[$c] = $col[1] ;
    	// extract and formate begin time from 07:00 to 0730
    	$begh = substr($col[2],0,2);
    	if (intval(substr($col[2],3,2))==30) $begm="30"; else $begm="00";
    	$begresa[$c] = $begh.$begm;
    	// extract and formate end time from 07:00 to 0730
    	$endh = substr($col[3],0,2);
    	if (intval(substr($col[3],3,2))==30) $endm="30"; else $endm="00";
    	// Formula to calculate number of boxes to set
    	$begtmp = intval($begh.$begm);
    	$endtmp = intval($endh.$endm);
    	$ecart  = ($endtmp - $begtmp)/100;
    	$intpart = intval($ecart);
    	$decpart = ($ecart - $intpart)*10;
    	$boxresa[$c] = $intpart *2-1; # <------- Modify in 1.4
    	if ( $decpart!=0 ) $boxresa[$c]++; 
    	$c++;
    }
     
    $c = 0; $odd=1;
     
    for ( $t=$begrange ; $t<$endrange ; $t++)
    {
    	$view = sprintf ( $viewbutton, $idresa[$c]);
     
    	/* Full hour */
    	$curtime = $t *100 ;
    	$num="<BIG>".$t.":00</BIG>"; 
    	if ( $begresa[$c]==strval($curtime) ) {
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font, $titleresa [$c], $view); 
    		$nextline = 1 ; 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	elseif ( $nextline && $boxresa[$c]!=0 ) {
    		$boxresa[$c]--;
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font,"&nbsp;","&nbsp;"); 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	else printf ($lineNO, $num, $bkcolorroom, $ftcolorroom,
    			$style ['notreserved'], $font, $t, "00");
     
    	$view = sprintf ( $viewbutton, $idresa[$c]);
     
    	/* Half hour */
    	$curtime = $curtime+30;
    	$num="<SMALL>".$t.":30</SMALL>"; 
    	if ( $begresa[$c]==strval($curtime) ) {
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom,
    			$style ['reserved'.$odd], $font, $titleresa [$c], $view); 
    		$nextline = 1 ; 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	elseif ( $nextline && $boxresa[$c]!=0 ) {
    		$boxresa[$c]--;
    		printf ($lineOK, $num, $bkcolorroom, $ftcolorroom, 
    			$style ['reserved'.$odd], $font, "&nbsp;", "&nbsp;"); 
    		if ( $boxresa[$c]==0 ) { 
    			$c++; 
    			$nextline=0; 
    			if ( $odd ) $odd=0; else $odd=1;
    		} 
    	}
    	else printf ($lineNO, $num, $bkcolorroom, $ftcolorroom,
    			$style ['notreserved'], $font, $t, "30");
    }
     
    ?>
    	</TBODY>
    </TABLE>

Discussions similaires

  1. [MySQL] Problème d'affichage dans la table à la suite de requetes.
    Par car0line dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 15/05/2009, 13h22
  2. problème date affichage requete
    Par Maria1505 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 26/07/2007, 20h55
  3. [MySQL] Problème d'affichage dans un boucle while
    Par Yagami_Raito dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 25/05/2007, 08h31
  4. [SQL] débutante: Problème d'affichage de requete
    Par katie dans le forum PHP & Base de données
    Réponses: 25
    Dernier message: 20/09/2006, 22h21
  5. Problème d'affichage redondant (genre boucle)
    Par EJ dans le forum XSL/XSLT/XPATH
    Réponses: 13
    Dernier message: 01/06/2004, 11h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo