
le 16/07/2008 à 13:20
jackbocar
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tableau PDO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
BODY {background: #f1f1f1;}
IMG {float: left;}
BODY, P, IMG {font-family: Arial, Helvetica, sans-serif;font-size: 10pt;margin: 0.5em;text-align:justify;}
.red {color: red;}
.cellule {color: #0C034F;text-align: justify;border: solid 1px #a0522d;}
.cadre {border: solid 1px #a0522d;background-color:#ffffff;}
.Lnav {text-decoration: none;font-weight: bold;color:#23698B;font-size : 10pt;}
.Lnav:hover {text-decoration: underline;font-weight: bold;color:#990000;font-size : 10pt;}
</style>
</head>
<body>
Bonjour,
J'ai un tableau en PDO, il fonctionne parfaitement bien, mon seul problème est les STYLES du cadre et des cellules. Ils sont pour une part épais et pour une autre fin ?
Comment régler ce problème ?
Merci de votre aide
Jack Bocar
--
-- Structure de la table `tableau_1`
--
CREATE TABLE `tableau_1` (
`id` int(11) NOT NULL auto_increment,
`Nouvelles` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tableau PDO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
BODY {background: #f1f1f1;}
IMG {float: left;}
BODY, P, IMG {font-family: Arial, Helvetica, sans-serif;font-size: 10pt;margin: 0.5em;text-align:justify;}
.red {color: red;}
.cellule {color: #0C034F;text-align: justify;border: solid 1px #a0522d;}
.cadre {border: solid 1px #a0522d;background-color:#ffffff;}
.Lnav {text-decoration: none;font-weight: bold;color:#23698B;font-size : 10pt;}
.Lnav:hover {text-decoration: underline;font-weight: bold;color:#990000;font-size : 10pt;}
</style>
</head>
<body>
Bonjour,
J'ai un tableau en PDO, il fonctionne parfaitement bien, mon seul problème est les STYLES du cadre et des cellules. Ils sont pour une part épais et pour une autre fin ?
Comment régler ce problème ?
Merci de votre aide
Jack Bocar
- <?php
- /*------------------------------------------------*/
- /*
- /* NE RIEN CHANGER ICI */
- /*
- /*------------------------------------------------*/
- class Connexion extends PDO{
- private $debug;
- /*--- constructeur ne rien changer ----*/
- function __construct($user,$mdp,$bdd,$host='localhost'){
- $this->debug=false;
- try{
- parent::__construct('mysql:host='.$host.';dbname='.$bdd,$user,$mdp);
- } catch(PDOEXCEPTION $e){
- die ('Erreur : '.$e->getMessage() );
- }
- $this->exec('SET CHARACTER SET 8859-1');
- }
- function modeDebug(){
- $this->debug=true;
- }
- /*--- execute une requete sql du type insert, delete ou update ---*/
- function exec($requete){
- $resultat=parent::exec($requete);
- if($resultat===FALSE and $this->debug){
- var_dump($resultat);
- var_dump(parent::errorInfo());
- }else{
- return $resultat;
- }
- }
- /*--- execute une requete du type select ---*/
- function query($requete){
- $resultat=parent::query($requete);
- if($resultat===FALSE and $this->debug){
- var_dump($this->errorInfo());
- var_dump(parent::errorInfo());
- $resultat->closeCursor();
- }else{
- return $resultat;
- }
- }
- /*--- return : false si aucune valeur trouvee ----*/
- function querySimple($select,$table,$where='',$groupBy='',$ordre='',$limit='',$defaut=false){
- $requete='select '.$select.
- ' from '.$table;
- if($where!=''){
- $requete.=' where '.$where;
- }
- if($groupBy!=''){
- $requete.=' group by '.$groupBy;
- }
- if($ordre!=''){
- $requete.=' order by '.$ordre;
- }
- if($limit!=''){
- $requete.=' limit '.$limit;
- }
- $resultat=$this->query($requete);
- $resultat=$resultat->fetchAll(PDO::FETCH_BOTH);
- if(isset($resultat[0][0])){
- return $resultat[0][0];
- }else{
- return $defaut;
- }
- }
- /*--- renvoie un tableau associatif contenant le résultat de la requete -----*/
- function requete2tableau($requete){
- $resultat=$this->query($requete);
- if($resultat===false AND $this->debug){
- echo $requete;
- };
- return $resultat->fetchAll(PDO::FETCH_ASSOC);
- }
- /*---renvoie un tableau html contenant le résultat de la requete---*/
- /*----ON PEUT MODIFFIER LA TABLE SEULEMENT ----*/
- function requete2html($requete,$border=0,$enteteColonne=true){
- $resultat=$this->query($requete);
- $texte='';
- $texte.= '<center><table width="90%" cellpadding="0" cellspacing="0" border="'.$border.'" class="cadre">';
- if($enteteColonne){
- $texte.= '<tr valign="top">';
- for($i=0;$i<$resultat->columnCount();$i++){
- $col=$resultat->getColumnMeta($i);
- $texte.= '<th class="red">'.$col['name'].'</th>';
- }
- $texte.= '</tr>';
- }
- $resultat->setFetchMode(PDO::FETCH_NUM);
- foreach($resultat as $ligne){
- $texte.= '<tr valign="top">';
- foreach($ligne as $valeur){
- $texte.= '<td class="cellule"><p>'.nl2br($valeur).'</p></td>';
- }
- $texte.= '</tr>';
- /*-- espace vide entre chaque tableau ----*/
- $texte.='<tr><td> </td></tr>';
- /*---ON PEUT MODIFIER LES ARGUMENTS SELECT ---*/
- }
- $resultat->closeCursor();
- $texte.='</table><br /><a href="#" class="Lnav">Top</a></center>';
- return $texte;
- }
- }
- $connexion=new Connexion('LOGIN','PASSWORD','BASE');
- $connexion->modeDebug();
- echo $connexion->requete2html('select id,Nouvelles as Nouvelles from tableau_1 ORDER BY id DESC',1);
- /*-
- ID, NEWS, INFO, OU TOUT AUTRE SUIVANT LA TABLE ON PEUT AUSSI AJOUTER DES ARGUMENTS
- -*/
- ?>
- <br />
- <a href="tableau_2.php" class="Lnav">Tableau 2</a> <a href="tableau_3.php" class="Lnav">Tableau 3</a> <a href="tableau_4.php" class="Lnav">Tableau 4</a>
- <br /><br />
- </body>
- </html>
--
-- Structure de la table `tableau_1`
--
CREATE TABLE `tableau_1` (
`id` int(11) NOT NULL auto_increment,
`Nouvelles` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;