Page 1 sur 2
appel fonction ds un autre fichier
Posté : 18 mars 2006, 11:00
par GoldWel
Bonjour,
j'aimerais faire appel a cette fonction qui se trouve dans un fichier StructuresFormations.php
Pouvez-me dire comment faire svp ?
function getGroupeUE($code_ue,$id_user,$profil){
$lesGroupes=array();
if($profil!='Administrateur'){
$rqt="select groupe.*
from groupe,groupe_etudiant
where groupe_etudiant.code_ue='".$code_ue."'
and groupe_etudiant.id_utilisateur='".$id_user."'
and groupe.code_ue='".$code_ue."'
and groupe_etudiant.numgroupe=groupe.numgroupe";
}
else{
$rqt="select groupe.*
from groupe
where groupe.code_ue='".$code_ue."'";
}
Posté : 18 mars 2006, 11:02
par GoldWel
Non, pardon, cest cette fonction que j'ai besoin de faire appel
function getLesAnnees($id_mention){
$lesAnnees=array();
$rqt="select annee_etude.id_annee,numannee,mention.nom_mention ,mention.nom_diplome
from annee_etude,mention
where annee_etude.id_mention=".$id_mention."
and mention.id_mention=".$id_mention;
$resultSet=mysql_query($rqt);
if(mysql_error()) echo mysql_error();
while($uneAnnee=mysql_fetch_array($resultSet)){
$uneAnnee['type']='annee';
$specialite=getSpecialite($uneAnnee['id_annee']);
$uneAnnee[1]=$uneAnnee['nom_diplome']." ".$uneAnnee['numannee']." mention ".$uneAnnee['nom_mention'];
if(!empty($specialite)) $uneAnnee[1].=" parcours ".$specialite['NOM_SPECIALITE'];
array_push($lesAnnees,$uneAnnee);
}
return $lesAnnees;
}
Posté : 18 mars 2006, 11:13
par Truc
tu inclus le fichier "StructuresFormations.php" puis tu peux appeler la foinction comme ceci:
$tab = array();
$tab = getLesAnnees($id_mention);
Posté : 18 mars 2006, 11:20
par GoldWel
Voila j'ai mis ça :
include("./structuresFormations/structuresFormations.php");
$tab = array();
$tab = getLesAnnees($id_mention);
et j'obtien toujours des msg d erreur :
Fatal error: Cannot redeclare getlesannees() (previously declared in c:\wamp\www\site\structuresFormations\structuresFormations.php:9) in c:\wamp\www\site\structuresFormations\structuresFormations.php on line 31
Je ne comprend pas
Posté : 18 mars 2006, 11:42
par Truc
la fonction est déja présente dans le fichier où elle est appelée, soit par include soit directement dans la page.
Posté : 18 mars 2006, 12:30
par GoldWel
Ah ben c bizarre, puisque la fonction n'est pas appellé et n'est pas présente du tout ds mon fichier.
include("./structuresFormations/structuresFormations.php");
$tab = array();
$tab = getLesAnnees($id_mention);
J'ai que ça qui fait référence au fichier StructuresFormations.php ou a ma fonction getLesAnnees. Dc, cest pa possible qu'il y a appel autre part ds mon fichier
Posté : 18 mars 2006, 12:38
par GoldWel
Bon, au fait, jai trouvé, fallait mettre un iclude_once :
include_once("./structuresFormations/structuresFormations.php");
mais je sai pas comment faire pr recup mes donnéees tjrs de la fonction suivante :
function getLesAnnees($id_mention){
$lesAnnees=array();
$rqt="select annee_etude.id_annee,numannee,mention.nom_mention ,mention.nom_diplome
from annee_etude,mention
where annee_etude.id_mention=".$id_mention."
and mention.id_mention=".$id_mention;
$resultSet=mysql_query($rqt);
if(mysql_error()) echo mysql_error();
while($uneAnnee=mysql_fetch_array($resultSet)){
$uneAnnee['type']='annee';
$specialite=getSpecialite($uneAnnee['id_annee']);
$uneAnnee[1]=$uneAnnee['nom_diplome']." ".$uneAnnee['numannee']." mention ".$uneAnnee['nom_mention'];
if(!empty($specialite)) $uneAnnee[1].=" parcours ".$specialite['NOM_SPECIALITE'];
array_push($lesAnnees,$uneAnnee);
}
return $lesAnnees;
}
Posté : 18 mars 2006, 13:51
par Truc
comme je l'ai montré:
$tab = array();
$tab = getLesAnnees($id_mention);
ensuite les données sont dans $tab, sous forme de tableau:
Regarde ce que donne:
<pre>
<? var_dump($tab); ?>
</pre>
Posté : 18 mars 2006, 13:55
par GoldWel
Le code suivant :
include_once("./structuresFormations/structuresFormations.inc.php");
$tab = array();
$tab = getLesAnnees($id_mention);
?>
<pre>
<? var_dump($tab); ?>
</pre>
et donne les erreurs :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and mention.id_mention=' at line 4
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\wamp\www\site\structuresFormations\structuresFormations.inc.php on line 162
array(0) {
}
Posté : 18 mars 2006, 14:04
par Truc
faut renseigner la variable $id_mention avec un id qui est en BD

Posté : 18 mars 2006, 14:15
par GoldWel
Ok, j'ai associé la variable $id_mention à une id de la BD : 1
include_once("./structuresFormations/structuresFormations.inc.php");
$id_mention = "1";
$tab = array();
$tab = getLesAnnees($id_mention);
?>
<pre>
<? var_dump($tab); ?>
</pre>
et cela m'affiche :
array(2) {
[0]=>
array(9) {
[0]=>
string(1) "3"
["id_annee"]=>
string(1) "3"
[1]=>
string(37) "LICENCE 3 mention STIC parcours MIAGE"
["numannee"]=>
string(1) "3"
[2]=>
string(4) "STIC"
["nom_mention"]=>
string(4) "STIC"
[3]=>
string(7) "LICENCE"
["nom_diplome"]=>
string(7) "LICENCE"
["type"]=>
string(5) "annee"
}
[1]=>
array(9) {
[0]=>
string(1) "8"
["id_annee"]=>
string(1) "8"
[1]=>
string(44) "LICENCE 3 mention STIC parcours Informatique"
["numannee"]=>
string(1) "3"
[2]=>
string(4) "STIC"
["nom_mention"]=>
string(4) "STIC"
[3]=>
string(7) "LICENCE"
["nom_diplome"]=>
string(7) "LICENCE"
["type"]=>
string(5) "annee"
}
}
Posté : 18 mars 2006, 14:17
par GoldWel
Fodré ke ca m'affiche les données suivantes :
LICENCE 3 mention STIC parcours MIAGE
LICENCE 3 mention STIC parcours Informatique
Posté : 18 mars 2006, 14:40
par Truc
regardes la fonction
foreach() il y a des exemples dans la doc, fait quelques tests et reviens si tu n'y arrives pas

Posté : 18 mars 2006, 18:46
par GoldWel
Oui g regardé le lien pr voir comment on utilise la fonction foreach() mais franchement je ne sai scomment m'y prendre.
Dsl, de vs faire perdre votre tps mais je suis debutant
Posté : 18 mars 2006, 20:14
par Truc
Dsl, de vs faire perdre votre tps mais je suis debutant
C'est surtout parce que je voulais que tu manipules un peu toi, on apprend toujours mieux si l'on à essayé des choses
$tab est un tableau à 2 dimensions il y a donc un sous tableau.
Il faut donc parcourir tout le 1er tableau pour récupérer tous les sous taleaux et enfin récupérer la valeur qui se trouve en [1].
foreach($tab as $cle => $val)
echo $tab[$cle][1]."<br />";