Récupération de données dans mes fonctions
Résolu
sinifer
Messages postés
323
Statut
Membre
-
sinifer Messages postés 323 Statut Membre -
sinifer Messages postés 323 Statut Membre -
Bonjour,
J'ai un petit problème j'avais créer un tableau qui me donne les résultats dans différentes bdd ce qui marchait très bien.
j'avais fait une fonction ou j'avait mis tous mon code et en paramètre de ma fonction je changé les différente données suivant les bdd.
j'usqu'à là tou va très bien j'ai fai mes résultats tous marche nickel mais maintenant je veu faire un resultat de tous les résultats de mes différents tableau et là je block depuis plus de 3h et c'est pour celà que je fais appel a votre aide.
donc j'ai deux fonction la première c'est la connextion a la bdd
la deuxième est la création de mon tableau avec son affichage.
voilà mon code pour ma deuxième fonction:
<?php
// creation de la function
function stats_pays($condition, $prefixe )
{
// REQUETE 1 :
$query = " ";
$result_vg = mysql_query($query) ;
while ($row = mysql_fetch_array($result_vg))
{
// REQUETE 2 :
$query_produit = " ";
$result = mysql_query($query_produit) ;
while ($row1 = mysql_fetch_array($result))
{
?>
<tr>
<td style="background-color:#CCCCCC;"> </td>
<td style="text-align:center;"> <?php echo $row['Origin'] ?> </td>
<td style="text-align:center;"> <?php echo $row['effectif_vg'] ?> </td>
<td style="text-align:center;"> <?php echo $row1['command'] ?> </td>
</tr>
<?php
$total_command += $row1["command"]; $total_effectif_vg += $row["effectif_vg"]; $total_conv = (($total_command/ $total_effectif_vg) * 100);
}
}
?>
<tr>
<td style="background-color:#CCCCCC; text-align: center; font-weight:bold;"> Total </td>
<td style="text-align:center;background-color:#CCCCCC;"> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_effectif_vg ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_command ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo round ($total_conv,2) ?> % </td>
</tr>
</table>
</br></br></br>
<?php
}
?>
donc jusque là tous va très bien mon tableau s'affiche bien quand je fait l'appel comme celà:
Code :
<?php connexionBase("localhost","root","mysql", "france") ;?>
<?php stats_pays( $condition) ; ?>
<?php connexionBase("localhost","root","mysql", "suisse") ;?>
<?php stats_pays( $condition) ; ?>
<?php connexionBase("localhost","root","mysql", "belgic") ;?>
<?php stats_pays( $condition) ; ?>
j'ai tous les résultats correct mais maintenant je veu créer un nouveau tableau avec les résultats de
Code :
<tr>
<td style="background-color:#CCCCCC; text-align: center; font-weight:bold;"> Total </td>
<td style="text-align:center;background-color:#CCCCCC;"> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_effectif_vg ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_command ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo round ($total_conv,2) ?> % </td>
</tr>
</table>
mais en accumulé donc sur chaque pays france suisse belgic
donc le total de $total_effectif_vg (france) + $total_effectif_vg (suisse) + $total_effectif_vg belgic
mais j'arrive pas à le faire et arrive pas a sortir les résultat en dehor de la fonction.
si quelqu'un(e) pourrait m'aider svp ce serai gentille
J'ai un petit problème j'avais créer un tableau qui me donne les résultats dans différentes bdd ce qui marchait très bien.
j'avais fait une fonction ou j'avait mis tous mon code et en paramètre de ma fonction je changé les différente données suivant les bdd.
j'usqu'à là tou va très bien j'ai fai mes résultats tous marche nickel mais maintenant je veu faire un resultat de tous les résultats de mes différents tableau et là je block depuis plus de 3h et c'est pour celà que je fais appel a votre aide.
donc j'ai deux fonction la première c'est la connextion a la bdd
la deuxième est la création de mon tableau avec son affichage.
voilà mon code pour ma deuxième fonction:
<?php
// creation de la function
function stats_pays($condition, $prefixe )
{
// REQUETE 1 :
$query = " ";
$result_vg = mysql_query($query) ;
while ($row = mysql_fetch_array($result_vg))
{
// REQUETE 2 :
$query_produit = " ";
$result = mysql_query($query_produit) ;
while ($row1 = mysql_fetch_array($result))
{
?>
<tr>
<td style="background-color:#CCCCCC;"> </td>
<td style="text-align:center;"> <?php echo $row['Origin'] ?> </td>
<td style="text-align:center;"> <?php echo $row['effectif_vg'] ?> </td>
<td style="text-align:center;"> <?php echo $row1['command'] ?> </td>
</tr>
<?php
$total_command += $row1["command"]; $total_effectif_vg += $row["effectif_vg"]; $total_conv = (($total_command/ $total_effectif_vg) * 100);
}
}
?>
<tr>
<td style="background-color:#CCCCCC; text-align: center; font-weight:bold;"> Total </td>
<td style="text-align:center;background-color:#CCCCCC;"> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_effectif_vg ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_command ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo round ($total_conv,2) ?> % </td>
</tr>
</table>
</br></br></br>
<?php
}
?>
donc jusque là tous va très bien mon tableau s'affiche bien quand je fait l'appel comme celà:
Code :
<?php connexionBase("localhost","root","mysql", "france") ;?>
<?php stats_pays( $condition) ; ?>
<?php connexionBase("localhost","root","mysql", "suisse") ;?>
<?php stats_pays( $condition) ; ?>
<?php connexionBase("localhost","root","mysql", "belgic") ;?>
<?php stats_pays( $condition) ; ?>
j'ai tous les résultats correct mais maintenant je veu créer un nouveau tableau avec les résultats de
Code :
<tr>
<td style="background-color:#CCCCCC; text-align: center; font-weight:bold;"> Total </td>
<td style="text-align:center;background-color:#CCCCCC;"> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_effectif_vg ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo $total_command ?> </td>
<td style="text-align:center; background-color:#CCCCCC; font-weight:bold;"> <?php echo round ($total_conv,2) ?> % </td>
</tr>
</table>
mais en accumulé donc sur chaque pays france suisse belgic
donc le total de $total_effectif_vg (france) + $total_effectif_vg (suisse) + $total_effectif_vg belgic
mais j'arrive pas à le faire et arrive pas a sortir les résultat en dehor de la fonction.
si quelqu'un(e) pourrait m'aider svp ce serai gentille
Configuration: Windows XP Firefox 3.0.11
12 réponses
-
à la fin de ta fonction stats_pays (juste avant le dernier }), tu ajoutes
return $total_effectif_vg;
et ensuite, tu fais
<?php connexionBase("localhost","root","mysql", "france") ;
$france=stats_pays( $condition) ;
connexionBase("localhost","root","mysql", "suisse") ;
$suisse=stats_pays( $condition) ;
connexionBase("localhost","root","mysql", "belgic") ;
$belgic=stats_pays( $condition) ;
$letotal = $france+$suisse+$belgic;
?> -
ok merci sa marche bien mais mon problème c'est que je veu pas seulement pour $total_effectif_vg; mais aussi pour $total_command et $total_conv;
et si je fais 3 return il sera pas quel est la bonne non?? -
ok merci de m'avoir mis sur la bonne voie c'est bon j'ai réussit comme sa:
return array($total_effectif_vg, $total_command, $total_conv, $total_CA, $total_Mmc);
php connexionBase("localhost","root","mysql", "france") ;
list($tt_ef_nl, $tt_comm_nl, $tt_conv_nl, $tt_ca_nl, $tt_mmc_nl )=stats_pays( $condition)
bonne journée -
Ben tu retournes un tableau :
au début de ta fonction tu fais var tableau = array();
quand tu as récupéré tes variables $total_command, $total_effectif_vg et $total_conv, tu fais, par exemple,
tableau['total_command'] = $total_command;
tabtableau['total_effectif_vg'] = $total_effectif_vg;
tableau['total_conv'] = $total_conv;
tu retourne ton tableau à la fin de la fonction
et pour récupérer les variables, tu fais :
<?php connexionBase("localhost","root","mysql", "france") ;
list( $total_command_france, $total_effectif_vg_france, $total_conv_france)=stats_pays( $condition) ;
connexionBase("localhost","root","mysql", "suisse") ;
list( $total_command_suisse, $total_effectif_vg_suisse, $total_conv_suisse)=stats_pays( $condition) ;
connexionBase("localhost","root","mysql", "belgic") ;
list( $total_command_belgic, $total_effectif_vg_belgic, $total_conv_belgic)=stats_pays( $condition) ;
?> -
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
Arf j'suis trop lent ^^
-
Merci en tous cas.
sais-tu comment faire pour que ça marche sa ??
car j'arrive pas à le faire marché
<?php
$v = "fr" ;
list($tt_ef_.$v, $tt_comm_nl, $tt_conv_nl, $tt_ca_nl, $tt_mmc_nl)=stats_pays( $condition) ;?>
car je veu définir la var v en fr et sur mon appel je veu que le nl s'affiche par le $v mais sa marche pas sa me met cette erreur
Parse error: parse error, expecting `','' or `')'' -
list(${$tt_ef_.$v}, $tt_comm_nl, $tt_conv_nl, $tt_ca_nl, $tt_mmc_nl)=stats_pays( $condition) ;
-
Merci
mais quand je fais mon echo $tt_ef_fr;
sa me mets ce message d'erreur:
Notice: Undefined variable: tt_ef_fr -
ha oui dsl, je croyais que la partie tt_ef_ était aussi variable
alors c'est ${'$tt_ef_'.$v} -
Merci mais sa me mets toujours la même erreur
Notice: Undefined variable: tt_ef_fr -
Dsl je me suis encore gouré en copiant (pas réveillé ce matin ...)
${'tt_ef_'.$v}
sans le $ du départ -
en plus j'étais sur d'avoir essayer sa.
Merci en tous cas c'étais sa parfait
et désolé de t'avoir tant solicité avec ton réveil difficile mais éspère que ta journée soit bonne en tous cas grace a toi moi je vais passé une bonne ;)