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 :

Retour BDD dans mail ecraser


Sujet :

PHP & Base de données

  1. #1
    Membre averti
    Homme Profil pro
    visiteur
    Inscrit en
    Janvier 2013
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : visiteur

    Informations forums :
    Inscription : Janvier 2013
    Messages : 19
    Par défaut Retour BDD dans mail ecraser
    Bonjour,

    voilà mon souci,
    J'ai une page client qui affiche sa commande correctement avec un retour d'une BDD.
    J'ai repris le même bout de code qui affiche la liste des produits en email.
    (copie pour moi et le client)

    Mais pour le retour de la BDD, qu'une donnée s'affiche dans la liste ( le dernier article écrase les autres articles du coup ne sont pas marqués dans l'email!).

    Comment faire ???

    voici le code de la page client il fonctionne nickel :
    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
     
    for($i=0 ;$i < $nbArticles ; $i++)
    {
    	require('../includes/PDO.php');
    	$req=('SELECT * FROM produits WHERE id="'.$_SESSION['panier']['libelleProduit'][$i].'"');
    	$sql=$pdo->query($req);
    	$retour=$sql->fetch(PDO::FETCH_ASSOC);
    	echo '<tr><td width="30%" height="5" align="left"><br><strong>'.$retour['variete'].'</strong></td>';
    	echo '<td width="30%" height="5" align="center"><br><input type="text" style="width:20px;" name="q[]" maxlength="1" value="'.($_SESSION['panier']['qteProduit'][$i]).'" disabled/></td>';
    	echo '<td width="30%" height="5" align="center"><br><strong>'.htmlentities(number_format($_SESSION['panier']['prixProduit'][$i],2)).' frs</strong></td></tr>';
    }
    echo '<tr><td colspan="4" height="1" bgcolor="#000000"></td></tr>';
    echo '<tr><td colspan="2" height="5" align="right"><br><span style="font-size: 14px;">+ Frais de port :</span><br></td>';
    echo '<td height="5" colspan="1" align="center"><br><strong><span style="font-size: 14px;">10.- frs</span></strong></td></tr>';
    echo '<tr><td height="5" colspan="2" align="right"><strong><span style="font-size: 16px;">Total :</span></strong><br>';
    echo '<td height="5" colspan="1" align="center" bgcolor="#CCCCCC"><strong>
    <span style="font-size: 14px;">'.number_format(MontantGlobal(),2).' frs</span></strong><br>';
    echo '</td></tr>';
    }
    et voici en image :

    Nom : Cap1.JPG
Affichages : 109
Taille : 23,9 Ko

    voici le code de la fonction mail variable $message :
    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
     
    for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++)
    	{
    	require('PDO.php');
    	$req = ('SELECT * FROM produits WHERE id="'.$_SESSION['panier']['libelleProduit'][$i].'"');
    	$sql = $pdo->query($req);
    	$retour = $sql->fetch(PDO::FETCH_ASSOC);
    	$message = '
    	<html><head><title></title></head><body>
    	<table width="80%" height="100%" align="center" bgcolor="#FFFFFF" style="font-size:15px; border-radius:5px;"><tr>
    	<td height="100%" align="center" colspan="100%">
    	<img src="'.ROOTPATH.'/images/gif/logo.png" width="50" height="50"><br><strong>Bonjour  '.sprintf($civil).' '.sprintf($nom).',
    	<br>Voici une copie de votre commande.</strong></div><br>
    	<div align="left">  <strong>'.sprintf($civil).' '.sprintf($nom).'</strong><br>
    	  <strong>'.sprintf($rue).'</strong><br>  <strong>'.sprintf($cp).' '.sprintf($ville).'</strong><br> <strong>
    	Tél. 0'.sprintf($telephone).'</strong><br>  <strong><span class="lien">'.sprintf($mail).'</strong>
    	<br><br>  <strong>'.sprintf($lois).'</strong>  <img src="'.ROOTPATH.'/images/gif/ok.png" width="15" height="15"/></td></tr><tr>
    	<td width="50%" colspan="3" valign="top" bgcolor="#CCFFCC" style="border: solid 1px black; border-radius:6px; text-align:center;">
    	<div height="5" align="center" bgcolor="CCFFCC"><span style="font-size:16px;"><strong>Vos produits :</strong></span></div></td></tr><tr>
    	<td width="10%" height="5" bgcolor="#CCCCCC"><strong>Variétés</strong></td>
    	<td width="10%" align="center" height="5" bgcolor="#CCCCCC"><strong>Quantité</strong></td>
    	<td width="10%" align="center" height="5" bgcolor="#CCCCCC"><strong>Prix/pce</strong></td></tr><tr><td width="30%" height="1%" align="left"><br>
    	<strong>'.$retour['variete'].'</strong></td><td width="30%" height="1%" align="center"><br>
    	<input type="text" style="width:10px;" name="q[]" maxlength="1" value="'.sprintf($_SESSION['panier']['qteProduit'][$i]).'" disabled/></td>
    	<td width="30%" height="1%" align="center"><br><strong>'.sprintf($retour['prix']).' frs</strong></td></tr>
    	<tr><td colspan="4" height="1%" bgcolor="000000"></td></tr>
    	<tr><td colspan="2" align="right"><br><span style="font-size: 14px;">+ Frais de port :</span><br></td>
    	<td colspan="1" align="center"><br><strong><span style="font-size: 14px;">10.- frs</span></strong></td></tr>
    	<tr><td colspan="2" align="right"><strong><span style="font-size: 16px;">Total :</span></strong><br><td colspan="1" align="center" bgcolor="#CCCCCC">
    	<strong><span style="font-size: 14px;">'.sprintf(number_format(MontantGlobal(),2)).' frs</span></strong><br>
    	</td></tr></tr><tr><td colspan="4"><div align="left"><br>Le colis et la facture vous sera envoyé par la Post dans les 3-4 jours ouvrables.<br></div>
    	<div align="center">En vous remerciant de votre confiance, je vous fais mes meilleures salutations.</div><br>
    	<div align="center"><strong>Le Webmaster</strong></div><br>
    	<div align="center" style="font-size:12px;">Si vous avez fais une erreur lors de votre commande, veuillez me contacter par téléphone ou par mail dans les 24 h.</div></td></tr></table></body></html>';
    	}
    et voilà en image de l'email:

    Nom : Cap2.JPG
Affichages : 85
Taille : 21,0 Ko

    Merci pour votre future aide !

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Il n'y a evidemment que la partie a repeter qui doit être dans la boucle.
    De plus il est judicieux ici d'utiliser une requête préparée.
    Et ne mets pas de sprintf partout.
    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
    <?php
    $message = '
    	<html><head><title></title></head><body>
    	<table width="80%" height="100%" align="center" bgcolor="#FFFFFF" style="font-size:15px; border-radius:5px;"><tr>
    	<td height="100%" align="center" colspan="100%">
    	<img src="'.ROOTPATH.'/images/gif/logo.png" width="50" height="50"><br><strong>Bonjour  '.$civil.' '.$nom.',
    	<br>Voici une copie de votre commande.</strong></div><br>
    	<div align="left">  <strong>'.$civil.' '.$nom.'</strong><br>
    	  <strong>'.$rue.'</strong><br>  <strong>'.$cp.' '.$ville.'</strong><br> <strong>
    	Tél. 0'.$telephone.'</strong><br>  <strong><span class="lien">'.$mail.'<strong>
    	<br><br>  <strong>'.$lois.'</strong>  <img src="'.ROOTPATH.'/images/gif/ok.png" width="15" height="15"/></td></tr><tr>
    	<td width="50%" colspan="3" valign="top" bgcolor="#CCFFCC" style="border: solid 1px black; border-radius:6px; text-align:center;">
    	<div height="5" align="center" bgcolor="CCFFCC"><span style="font-size:16px;"><strong>Vos produits :</strong></span></div></td></tr><tr>
    	<td width="10%" height="5" bgcolor="#CCCCCC"><strong>Variétés</strong></td>
    	<td width="10%" align="center" height="5" bgcolor="#CCCCCC"><strong>Quantité</strong></td>
    	<td width="10%" align="center" height="5" bgcolor="#CCCCCC"><strong>Prix/pce</strong></td></tr>';
     
    require('PDO.php');
    $sth = $pdo->prepare('SELECT * FROM produits WHERE id = :id');
    foreach ($_SESSION['panier']['libelleProduit'] as $key=>$id)
    	$result = $sth->execute(array(':id'=>$id));
    	$retour = $result->fetch(PDO::FETCH_ASSOC);
    	$message .= '<tr><td width="30%" height="1%" align="left"><br>
    	<strong>'.$retour['variete'].'</strong></td><td width="30%" height="1%" align="center"><br>
    	<input type="text" style="width:10px;" name="q[]" maxlength="1" value="'. $_SESSION['panier']['qteProduit'][$key].'" disabled /></td>
    	<td width="30%" height="1%" align="center"><br><strong>'. $retour['prix']. ' frs</strong></td></tr>';
    }
    $message .= '<tr><td colspan="4" height="1%" bgcolor="000000"></td></tr>
    	<tr><td colspan="2" align="right"><br><span style="font-size: 14px;">+ Frais de port :</span><br></td>
    	<td colspan="1" align="center"><br><strong><span style="font-size: 14px;">10.- frs</span></strong></td></tr>
    	<tr><td colspan="2" align="right"><strong><span style="font-size: 16px;">Total :</span></strong><br><td colspan="1" align="center" bgcolor="#CCCCCC">
    	<strong><span style="font-size: 14px;">'.sprintf(number_format(MontantGlobal(),2)).' frs</span></strong><br>
    	</td></tr></tr><tr><td colspan="4"><div align="left"><br>Le colis et la facture vous sera envoyé par la Post dans les 3-4 jours ouvrables.<br></div>
    	<div align="center">En vous remerciant de votre confiance, je vous fais mes meilleures salutations.</div><br>
    	<div align="center"><strong>Le Webmaster</strong></div><br>
    	<div align="center" style="font-size:12px;">Si vous avez fais une erreur lors de votre commande, veuillez me contacter par téléphone ou par mail dans les 24 h.</div></td></tr></table></body></html>';
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre averti
    Homme Profil pro
    visiteur
    Inscrit en
    Janvier 2013
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : visiteur

    Informations forums :
    Inscription : Janvier 2013
    Messages : 19
    Par défaut
    Merci sabotage pour votre réponse,
    J'ai essayer votre code ca n'a pas marché mais par contre j'ai effectuer mon code adapter sur la base de votre code et ca marche merci !

    Voici mon remplacement de code
    $message='.....';
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++)
    	{
    	require('PDO.php');
    	$req=('SELECT * FROM produits WHERE id="'.$_SESSION['panier']['libelleProduit'][$i].'"');
    	$sql=$pdo->query($req);
    	$retour=$sql->fetch(PDO::FETCH_ASSOC);
    	$message.='<tr><td width="30%" height="1%" align="left"><br>
    	<strong>'.$retour['variete'].'</strong></td><td width="30%" height="1%" align="center"><br>
    	<input type="text" style="width:10px;" name="q[]" maxlength="1" value="'.$_SESSION['panier']['qteProduit'][$i].'" disabled /></td>
    	<td width="30%" height="1%" align="center"><br><strong>'.$retour['prix'].'&nbsp;frs</strong></td></tr>';
    	}
    $message.='.....';

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Je ne sais pas trop ce qui n'a pas marché dans mon code mais ce que tu fais n'est pas bon.
    A minima, ne met pas l'include dans la boucle.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PHP 5.3] Retour à ligne dans un e-mail
    Par hanitax dans le forum Langage
    Réponses: 2
    Dernier message: 06/02/2013, 11h27
  2. Stocker un retour json dans une bdd
    Par Perplexe dans le forum Langage
    Réponses: 7
    Dernier message: 28/08/2009, 15h08
  3. retour ligne dans mail sous lotus
    Par fomy dans le forum VBA Access
    Réponses: 1
    Dernier message: 09/07/2008, 15h19
  4. [Mail] Retour chariot dans textearea
    Par teumm dans le forum Langage
    Réponses: 8
    Dernier message: 27/03/2007, 17h52
  5. Retour chariot dans un TMemo ?
    Par Vincent PETIT dans le forum C++Builder
    Réponses: 7
    Dernier message: 27/08/2002, 18h55

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