Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 24/03/2011, 11h45   #1
Invité de passage
 
Inscription : décembre 2010
Messages : 7
Détails du profil
Informations forums :
Inscription : décembre 2010
Messages : 7
Points : 0
Points : 0
Par défaut Affichage d'une requête dans un tableau HTML

Bonjour,

Je débute en PHP et je dois créer une page HTML qui affiche les données du table sous Access dans un tableau.

Dans un même fichier, j'ai fait :

Pour la connexio :

Code :
1
2
3
4
5
6
7
8
 
//connexion à une base de données ACCESS
$bdd = 'TEST'; // identifiant DSN
$user = 'ADMIN'; // login
$password = ''; // password
$cnx = odbc_connect($bdd , $user, $password ) or die('La connexion a échouée !<br />'.odbc_error()); // connexion
$query = 'SELECT MRQIDAPP, MRQNOM, MRQLIB, MRQFORMAT, MRQACTIF FROM OC_DATMARQUEUR'; //requête
$reponse = odbc_exec($cnx, $query) or die('Erreur SQL !<br />'.$query.'<br />'.odbc_error());
Voici maintenant le parcours de ma requête et la construction de mon tableau :
Code :
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
 
<table>
	<caption>Liste des marqueurs</caption>
		<thead>
			<tr>
			   <th>NOM</th>
			   <th>LIBELLE</th>
			   <th>FORMAT</th>
			   <th>ACTIF</th>
			</tr>
		</thead>
		<tfoot>
			<tr>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td></td>
			</tr>		   
		</tfoot>
		<?php
			// On affiche chaque entrée une à une
			while (odbc_fetch_array($reponse))
			{
		?>
		<tbody>
		   <tr>
			   <td><?php odbc_result($reponse, 2); ?></td>
			   <td><?php odbc_result($reponse, 3); ?></td>
			   <td><?php odbc_result($reponse, 4); ?></td>
			   <td><?php odbc_result($reponse, 5); ?></td>
		   </tr>
		</tbody>
	</table>
	<?php
	}
	odbc_close($cnx); // ferme la connexion
Malheureusement, je n'arrive pas à afficher mon tableau

Le message d'erreur n'est pas très explicite puisque ma page affiche mon code tel quel.
Code :
1
2
3
4
5
6
7
8
9
10
 
'.odbc_error()); // connexion $query = 'SELECT MRQIDAPP, MRQNOM, MRQLIB, MRQFORMAT, MRQACTIF FROM OC_DATMARQUEUR'; //requête echo '
'.$query.'
'; $reponse = odbc_exec($cnx, $query) or die('Erreur SQL !
'.$query.'
'.odbc_error()); ?>
Liste des marqueurs NOM 	LIBELLE 	FORMAT 	ACTIF
 
 
getMessage()); } ?>
Une âme charritable peut-elle me venir en aide ?
jplec est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/03/2011, 11h53   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Est-ce que ton fichier porte bien l'extension .php ?
Est-ce que ton code commence bien par <?php
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/03/2011, 12h43   #3
Invité de passage
 
Inscription : décembre 2010
Messages : 7
Détails du profil
Informations forums :
Inscription : décembre 2010
Messages : 7
Points : 0
Points : 0
Mon fichier se nomme ListeMarqueurs.php.

Voici le fichier complet :

Code :
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
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
   <head>
       <title>Liste des marqueurs</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   </head>
   <body>
		<?php
			try
			{
				//connexion à une base de données ACCESS
				$bdd = 'TEST'; // identifiant DSN
				$user = 'ADMIN'; // login
				$password = ''; // password
				$cnx = odbc_connect($bdd , $user, $password ) or die('La connexion a échouée !<br />'.odbc_error()); // connexion
				$query = 'SELECT MRQIDAPP, MRQNOM, MRQLIB, MRQFORMAT, MRQACTIF FROM OC_DATMARQUEUR'; //requête
				echo '<br />'.$query.'<br />';
				$reponse = odbc_exec($cnx, $query) or die('Erreur SQL !<br />'.$query.'<br />'.odbc_error()); 
				?>
				<table>
				<caption>Liste des marqueurs</caption>
				<thead>
					<tr>
					   <th>NOM</th>
					   <th>LIBELLE</th>
					   <th>FORMAT</th>
					   <th>ACTIF</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
					   <td></td>
					   <td></td>
					   <td></td>
					   <td></td>
					</tr>		   
				</tfoot>
				<?php
				// On affiche chaque entrée une à une
				while (odbc_fetch_array($reponse))
				{
					$nom    = odbc_result($reponse, 2);
					$lib    = odbc_result($reponse, 3);
					$format = odbc_result($reponse, 4);
					$actif  = odbc_result($reponse, 5);
 
					echo 'Nom : '.$nom;
				?>
					<tbody>
					   <tr>
						   <td><?php odbc_result($reponse, 2); ?></td>
						   <td><?php odbc_result($reponse, 3); ?></td>
						   <td><?php odbc_result($reponse, 4); ?></td>
						   <td><?php odbc_result($reponse, 5); ?></td>
					   </tr>
					</tbody>
				</table>
				<?php
				}
				odbc_close($cnx); // ferme la connexion
			}
			catch(Exception $e)
			{
				// En cas d'erreur précédemment, on affiche un message et on arrête tout
				die('Erreur : '.$e->getMessage());
			}
		 ?> 		
   </body>
</html>
Ce fichier est appelé à partir d'une autre page grâce à un lien hypertexte :

Code :
1
2
 
<li><a href="ListeMarqueurs.php">Liste des marqueurs</a></li>
jplec est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/03/2011, 14h07   #4
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Est ce que tu arrives a faire du php sur ton serveur en dehors de ce cas ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/03/2011, 15h59   #5
Invité de passage
 
Inscription : décembre 2010
Messages : 7
Détails du profil
Informations forums :
Inscription : décembre 2010
Messages : 7
Points : 0
Points : 0
Apparemment non !!!

J'ai testé cette page :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <title>Notre première instruction : echo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
        <h2>Affichage de texte avec PHP</h2>
 
        <p>
            Cette ligne a été écrite entièrement en (x)HTML.<br />
            <?php echo "Celle-ci a été écrite entièrement en PHP."; ?>
        </p>
    </body>
</html>
La ligne de PHP ne s'affiche pas !

J'utilise EasyPHP et je suis sous windows XP. A terme, mon application sera développée à l'ai de du ZendFramework.

Voici un extrait de ma configuration Apache :
Code :
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
 
ServerRoot "${path}/apache"
Listen 80 
 
LoadModule php5_module "${path}/php/php5apache2_2.dll"
 
DocumentRoot "D:/Dev/ZEND"
 
<Directory "D:/Dev/ZEND">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
 
# J'ai 2 virtualHost
<VirtualHost *:80>
   DocumentRoot "D:/Dev/ZEND/completude/public"
   ServerName .local
 
   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development
 
   <Directory "D:/Dev/ZEND/completude/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>
 
</VirtualHost>
 
<VirtualHost *:80>
   DocumentRoot "D:/Dev/ZEND/interface"
   ServerName .local
 
   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development
 
   <Directory "D:/Dev/ZEND/interface">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>
 
</VirtualHost>
Le 1er VirtualHost sert pour le projet sous ZF (manipulation des données8).
J'ai ajouté le second afin de créer mes fichiers PHP pour apprendre les rudiments du langage.

Je ne souhaitais pas que ces fichiers soient mélangés à ceux sous Zend.
jplec est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/03/2011, 20h50   #6
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Controle ton log apache pour voir s'il y a des erreurs.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/03/2011, 12h58   #7
Invité de passage
 
Inscription : décembre 2010
Messages : 7
Détails du profil
Informations forums :
Inscription : décembre 2010
Messages : 7
Points : 0
Points : 0
Voici un extrait du log apache :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
 
[Wed Mar 23 11:29:06 2011] [notice] Apache/2.2.17 (Win32) PHP/5.3.5 configured -- resuming normal operations
[Wed Mar 23 11:29:06 2011] [notice] Server built: Oct 18 2010 01:58:12
[Wed Mar 23 11:29:06 2011] [notice] Parent: Created child process 4108
[Wed Mar 23 11:29:06 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Wed Mar 23 11:29:06 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Wed Mar 23 11:29:07 2011] [notice] Child 4108: Child process is running
[Wed Mar 23 11:29:07 2011] [notice] Child 4108: Acquired the start mutex.
[Wed Mar 23 11:29:07 2011] [notice] Child 4108: Starting 64 worker threads.
[Wed Mar 23 11:29:07 2011] [notice] Child 4108: Starting thread to listen on port 80.
[Wed Mar 23 11:29:07 2011] [notice] Child 3120: All worker threads have exited.
[Wed Mar 23 11:29:07 2011] [notice] Child 3120: Child process is exiting
J'ai sans doute mal paramétré mon serveur
jplec est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h48.


 
 
 
 
Partenaires

Hébergement Web