1

Bonjour,
J'ai parcouru le forum mais je n'ai pas toruver de cas similaire.
Voilà ma problématique.
Je doit générer un catalogue de plusieurs pages... Et chaque pages doit afficher 2 produits provenant d'une base de données SQL
Actuellement j'arrive à générer le catalogue PDF avec 1 page par produit.

Votre aide me serait trés précieuse, MERCI

Voici mon code actuel : via une include


<?php


$db = mysql_connect('localhost', 'root', '');
mysql_select_db('***',$db);
$sql = "SELECT * FROM produit WHERE active='1' ORDER BY sousouscategorie ASC ";
$req=mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($data = mysql_fetch_assoc($req))
{
// on affiche les informations de l'enregistrement en cours
$id=$data['id'];
$nom=$data['nom'];
$plan=$data['plan'];
$categorie=$data['sousouscategorie'];
$categorie = mb_strtoupper($categorie, 'UTF-8');
?>
<style type="text/css">

table.page_header {width: 100%; border: none; background-color: #e1e1e1; border-bottom: solid 1mm #bcbcbc; padding: 2mm }
table.page_footer {width: 100%; border: none; background-color: #e1e1e1; border-top: solid 1mm #bcbcbc; padding: 2mm}
h3.note {border: solid 1mm #DDDDDD;background-color: #EEEEEE; padding: 2mm; border-radius: 2mm; width: 100%; }
ul.main { width: 95%; list-style-type: square; }
ul.main li { padding-bottom: 2mm; }
h1 {text-align: center; font-size: 20mm}
h3 {text-align: center; font-size: 12mm}
h5 {letter-spacing: 10px; text-align: center; font-size: 8mm}

</style>

<page backtop="20mm" backbottom="0mm" backleft="10mm" backright="10mm" style="font-size: 12pt">
<page_header>
<table class="page_header">
<tr>
<td style="width: 100%; text-align: center">
<h5><?php


echo preg_replace("/(.{1})/Ui", "$1&nbsp;", $categorie);?></h5>

</td>

</tr>
</table>
</page_header>
<page_footer>
<table class="page_footer">
<tr>
<td style="width: 33%; text-align: left;">
url
</td>
<td style="width: 34%; text-align: center">
page [[page_cu]] / [[page_nb]]
</td>
<td style="width: 33%; text-align: right">
&copy; CP France 2013 </td>
</tr>
</table>
</page_footer>
<br><br><table>
<tr><td><h3 class="note">&nbsp;<?php echo $id ;?>&nbsp;</h3></td></tr>
</table><br><br><br>

<table style="border-collapse:collapse;"border="1" align="center" width="100%">
<tr>
<td height=250 width=350 align="center">
<?php echo "<img width=\"200\" height=\"200\" src=\"imageProduits/$id.jpg\">"; ?>

</td>
<?php if (!empty($plan))
{
echo "<td height=250 width=350 align=\"center\"><img width=\"200\" height=\"200\" src=\"imageProduits/$id-zoom.jpg\"></td>";
}
?>
</tr>
</table>
<table width=100%>
<tr>
<td><h4><?php $Nom=str_replace ("***","Réf :","$nom"); echo $Nom; ?></h4></td>
</tr>
</table>
</page>
<?php
}
?>

2

Ben solution simple (un peu bateau, mais bon... au moins c'est facile à implémenter) il faut que tu aies un compteur intermédiaire que tu réinitialises dès que tu arrives à deux produits. Au début, le compteur est à zéro. A chaque produit, il s'incrémente. Quand tu arrives à deux produits, tu le remets à zéro et tu crées une nouvelle page.
Pour ça, je te renvoie aux structures conditionnelles en PHP, c'est très simple et assez indispensable...
avatar

3

Bonjour Et merci de votre réponse.
Dans la théorie c'est un peu ce que j'avais imaginer.
Mais dans la pratique, je suis pas sûr de savoir comment faire.
J'ai commencer quelque chose, mais je crois que je fait fausse route.
voici ou j'en suis :
<?php //récupération de $limite if(isset($_GET['limite'])) $limite=$_GET['limite']; else $limite=0; function verifLimite($limite,$total,$nombre) { // je verifie si limite est un nombre. if(is_numeric($limite)) { // si $limite est entre 0 et $total, $limite est ok // sinon $limite n'est pas valide. if(($limite >=0) && ($limite <= $total) && (($limite%$nombre)==0)) { // j'assigne 1 à $valide si $limite est entre 0 et $max $valide = 1; } else { // sinon j'assigne 0 à $valide $valide = 0; } } else { // si $limite n'est pas numérique j'assigne 0 à $valide $valide = 0; } // je renvois $valide return $valide; } $nombre = 2; // on va afficher 2 résultats par page. if (!isset($limite)) $limite = 0; // si on arrive sur la page pour la première fois // on met limite à 0. $path_parts = pathinfo($_SERVER['PHP_SELF']); $page = $path_parts['basename']; $db = mysql_connect('localhost', 'root', ''); mysql_select_db('***',$db); $select = "SELECT count(id) FROM produit WHERE active='1'"; $result = mysql_query($select) or die ('Erreur : '.mysql_error() ); $row = mysql_fetch_row($result); $total = $row[0]; $sql = "SELECT * FROM produit WHERE active='1' ORDER BY sousouscategorie ASC LIMIT $limite,$nombre"; $req=mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); while($data = mysql_fetch_assoc($req)) { // on affiche les informations de l'enregistrement en cours $id=$data['id']; $nom=$data['nom']; $plan=$data['plan']; $categorie=$data['sousouscategorie']; $categorie = mb_strtoupper($categorie, 'UTF-8'); $limitesuivante = $limite + $nombre; ?> <style type="text/css"> table.page_header {width: 100%; border: none; background-color: #e1e1e1; border-bottom: solid 1mm #bcbcbc; padding: 2mm } table.page_footer {width: 100%; border: none; background-color: #e1e1e1; border-top: solid 1mm #bcbcbc; padding: 2mm} h3.note {border: solid 1mm #DDDDDD;background-color: #EEEEEE; padding: 2mm; border-radius: 2mm; width: 100%; } ul.main { width: 95%; list-style-type: square; } ul.main li { padding-bottom: 2mm; } h1 {text-align: center; font-size: 20mm} h3 {text-align: center; font-size: 12mm} h5 {letter-spacing: 10px; text-align: center; font-size: 8mm} </style> <table> <tr><td><h3 class="note">&nbsp;<?php echo $id ;?>&nbsp;</h3></td></tr> </table> <table style="border-collapse:collapse;"border="1" align="center" width="100%"> <tr> <td height=250 width=350 align="center"> <?php echo "<img width=\"200\" height=\"200\" src=\"imageProduits/$id.jpg\">"; ?> </td> <?php if (!empty($plan)) { echo "<td height=250 width=350 align=\"center\"><img width=\"200\" height=\"200\" src=\"imageProduits/$id-zoom.jpg\"></td>"; } ?> </tr> </table> <table width=100%> <tr> <td><h4><?php $Nom=str_replace ("***","Réf :","$nom"); echo $Nom; ?></h4></td> </tr> </table><hr>

pouvez vous me mettre sur la bonne piste?
Merci

4

O_o je ne comprends pas du tout ce que tu cherches à faire... et j'ai un peu l'impression que tu ne sais pas du tout ce que tu fais non plus...
Ce dont tu as besoin prend à tout casser 3 lignes, pas besoin de ce je ne sais quoi...
avatar

5

Bonjour, SI je sais que je veux et j'ai compris mon erreur...
En fait l'erreur que j'ai commis est que j'ai place ma boucle WHILE avant la balise <table> alors qu'il fallait la démarrer àprès.
Du coup comme HTML2PDF à un saut de page automatique, ça fonctionne.
Merci quand même !

6

Parfait (par contre, si tu as gardé la façon de faire tu ./3, tu te compliques quand même sacrément la vie...).
avatar

7

J'utilise bibliothèque html2pdf pour la création de PDF. Comment je vais faire [[page_cu]] (page actuelle) comme un entier PHP en utilisant html2pdf.
En fait, je suis générer plusieurs pages à l'aide de boucles. donc je veux me cacher la page section pied de page sur la première page. Je ne peux pas obtenir numéro de page actuel et le total des pages comme un entier php.