par
moogli » 21 oct. 2016, 14:36
salut,
déjà cela ne peux pas fonctionner
$req = $bd->query('SELECT
et quelques lignes plus loin
$req = $bd->prepare('INSERT I
=> tu écrase le contenue du select.
il faut que tu parcours les résultats du select pour insérer dans la base
voilà a quoi peux ressembler ton code
<?php
$jour = $param["jour"];
$mois = $param["mois"];
$annee=date('Y');
$age_supp=$param["age_supp"];
$ladate= $annee.'-'.$mois.'-'.$jour;
$tranche1=50;
$_debut = 27000;
$_fin = 27550;
$type ="Noël salariés";
$distrib ="Non";
$stmtSelect = $bd->prepare('SELECT matricule, groupe, nom, prenom , date_entree, TIMESTAMPDIFF(YEAR,`date_entree`, :dte ) as anc
FROM membre
WHERE groupe="8-actif" and TIMESTAMPDIFF(YEAR,`date_entree`, :dte) >= :age
ORDER BY nom ASC, prenom ASC');
$stmtSelect->bindValue(':dte', $ladate);
$stmtSelect->bindValue(':age', $age_supp);
$stmtSelect->execute();
$stmtInsert = $bd->prepare('INSERT INTO archive SET
type = :type,
num_carnet= :num_carnet,
montant= :montant,
matricule= :matricule,
nom_parent= :nom_parent,
prenom_parent= :prenom_parent,
age= :age,
annee= :annee,
distrib= :distrib');
$stmtInsert->bindValue(':type', $type);
$stmtInsert->bindValue(':montant', $tranche1);
$stmtInsert->bindValue(':distrib', $distrib);
$stmtInsert->bindValue(':annee', $annee);
while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
if ($_debut == $_fin) {
// a priori t'es limité à 500 salariés au dessus y a rien :)
break;
}
$stmtInsert->bindValue(':num_carnet', $_debut);
$stmtInsert->bindValue(':matricule', $donnees['matricule']);
$stmtInsert->bindValue(':nom_parent', strtoupper($donnees['nom']));
$stmtInsert->bindValue(':prenom_parent', strtoupper($donnees['prenom']));
$stmtInsert->bindValue(':age', $donnees['anc']);
$stmtInsert->execute();
$_debut++;
}
$stmtSelect->closeCursor();
@+
salut,
déjà cela ne peux pas fonctionner
$req = $bd->query('SELECT
et quelques lignes plus loin
$req = $bd->prepare('INSERT I
=> tu écrase le contenue du select.
il faut que tu parcours les résultats du select pour insérer dans la base
voilà a quoi peux ressembler ton code
[php]<?php
$jour = $param["jour"];
$mois = $param["mois"];
$annee=date('Y');
$age_supp=$param["age_supp"];
$ladate= $annee.'-'.$mois.'-'.$jour;
$tranche1=50;
$_debut = 27000;
$_fin = 27550;
$type ="Noël salariés";
$distrib ="Non";
$stmtSelect = $bd->prepare('SELECT matricule, groupe, nom, prenom , date_entree, TIMESTAMPDIFF(YEAR,`date_entree`, :dte ) as anc
FROM membre
WHERE groupe="8-actif" and TIMESTAMPDIFF(YEAR,`date_entree`, :dte) >= :age
ORDER BY nom ASC, prenom ASC');
$stmtSelect->bindValue(':dte', $ladate);
$stmtSelect->bindValue(':age', $age_supp);
$stmtSelect->execute();
$stmtInsert = $bd->prepare('INSERT INTO archive SET
type = :type,
num_carnet= :num_carnet,
montant= :montant,
matricule= :matricule,
nom_parent= :nom_parent,
prenom_parent= :prenom_parent,
age= :age,
annee= :annee,
distrib= :distrib');
$stmtInsert->bindValue(':type', $type);
$stmtInsert->bindValue(':montant', $tranche1);
$stmtInsert->bindValue(':distrib', $distrib);
$stmtInsert->bindValue(':annee', $annee);
while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
if ($_debut == $_fin) {
// a priori t'es limité à 500 salariés au dessus y a rien :)
break;
}
$stmtInsert->bindValue(':num_carnet', $_debut);
$stmtInsert->bindValue(':matricule', $donnees['matricule']);
$stmtInsert->bindValue(':nom_parent', strtoupper($donnees['nom']));
$stmtInsert->bindValue(':prenom_parent', strtoupper($donnees['prenom']));
$stmtInsert->bindValue(':age', $donnees['anc']);
$stmtInsert->execute();
$_debut++;
}
$stmtSelect->closeCursor();[/php]
@+