Affichage data dans tableau HTML

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Affichage data dans tableau HTML

Re: Affichage data dans tableau HTML

par bigamber » 11 sept. 2009, 14:18

Merci, c'est exactement ce qu'il me fallait.

@++

Re: Affichage data dans tableau HTML

par Victor BRITO » 10 sept. 2009, 12:40

Corrige ton code au niveau de ta boucle while comme suit :
<table>
  <thead>
    <tr>
      <th scope="col">Niveau de licences</th>
      <th scope="col">Langue</th>
      <th scope="col">Famille de produit</th>
      <th scope="col">Désignation</th>
      <th scope="col">L/LSA/SA</th>
      <th scope="col">Points</th>
      <th scope="col">Famille de licences</th>
      <th scope="col">Réf. MS</th>
      <th scope="col">PME en euros</th>
    </tr>
  </thead>
  <tbody>
<?php
while ($data = mysql_fetch_array ($req)):
?>
    <tr>
      <td><?php echo $data['NIVEAU_DE_LICENCES'] ?></td>
      <td><?php echo $data['LANGUE'] ?></td>
      <td><?php echo $data['FAMILLE_DE_PRODUIT'] ?></td>
      <td><?php echo $data['DESIGNATION'] ?></td>
      <td><?php echo $data['L/LSA/SA'] ?></td>
      <td><?php echo $data['POINTS'] ?></td>
      <td><?php echo $data['FAMILLE_DE_LICENCES'] ?></td>
      <td><?php echo $data['REF_MS'] ?></td>
      <td><?php echo $data['PME_EN_EUROS'] ?></td>
    </tr>
<?php
endwhile;
?>
  </tbody>
</table>
Autrement dit, de part et d'autre de la boucle while, tu ouvres et fermes l'élément table, ainsi que l'élément tbody ; avant tbody, tu places un thead, dans lequel se trouvera une ligne (tr) contenant les cellules d'en-tête (th) ; au sein de la boucle while, tu ouvres et fermes l'élément tr, contenant un élément td par donnée à afficher pour la ligne en cours.

Affichage data dans tableau HTML

par bigamber » 10 sept. 2009, 12:08

Bonjour à tous,

Je faits une recherche dans ma base de données et je souhaierais afficher mes résultats dans un tableau HTML. Problème je n'y arrive pas !
Voici mon code
<?php 

//echo htmlentities($_POST['valeur']);
$produit=$_POST['produit'];

$licences=$_POST['licences'];
$ref=$_POST['ref'];

// on se connecte à MySQL 
$db = mysql_connect('localhost', 'root', 'mysql'); 

// on sélectionne la base 
mysql_select_db('tarifs',$db); 

// on crée la requête SQL 
$sql = "SELECT * FROM microsoft where FAMILLE_DE_PRODUIT like '%$produit%' AND FAMILLE_DE_LICENCES like '%$licences%' AND REF_MS like '%$ref%'";
//$sql = "SELECT * FROM microsoft where FAMILLE_DE_PRODUIT = $_POST['valeur']";

//$sql = "SELECT * FROM microsoft where $valeur"; 

// on envoie la requête 
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

// on fait une boucle qui va faire un tour pour chaque enregistrement 
while($data = mysql_fetch_array($req)) 
    { 
    // on affiche les informations de l'enregistrement en cours 

  echo '<b>'.$data['NIVEAU_DE_LICENCES'].'-'.$data['LANGUE'].'-'.$data['FAMILLE_DE_PRODUIT'].'-'.$data['DESIGNATION'].'-'.$data['L/LSA/SA'].'-'.$data['POINTS'].'-'.$data['FAMILLE_DE_LICENCES'].'-'.$data['REF_MS'].'-'.$data['PME_EN_EUROS'].'</i><br>'; 
//$NIVEAU = $data['NIVEAU_DE_LICENCES'];

	
	//array_push($tab,$data['NIVEAU_ DE_ LICENCES'].$data['FAMILLE_DE_PRODUIT']);
    } 

// on ferme la connexion à mysql 
mysql_close(); 
?> 
Et au lieu d'avoir un
  echo '<b>'.$data['NIVEAU_DE_LICENCES'].'-'.$data['LANGUE'].'-'.$data['FAMILLE_DE_PRODUIT'].'-'.$data['DESIGNATION'].'-'.$data['L/LSA/SA'].'-'.$data['POINTS'].'-'.$data['FAMILLE_DE_LICENCES'].'-'.$data['REF_MS'].'-'.$data['PME_EN_EUROS'].'</i><br>'; 
tout moche je voudrais que les résultats se retrouve dans un joli tableau.

J'ai bien essayé d'insérer des choses du type :
echo '<table>
<tr>
<th>NIVEAU_DE_LICENCES</th>
</tr>
<td><?php echo $data['NIVEAU_DE_LICENCES'];?></td>
Mais sans succès......