appel fonction ds un autre fichier

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : appel fonction ds un autre fichier

par Truc » 18 mars 2006, 20:36

et bien c'est parfait... maintenant tu peux traiter la variable :wink:

par GoldWel » 18 mars 2006, 20:34

J'ai cherch éun peu et finalement jai trouvé, voila mon code :


include_once("./structuresFormations/structuresFormations.inc.php");


$id_mention = "1";
$tab = array();
$tab = getLesAnnees($id_mention);
if(count($tab)>0) {
foreach($tab as $annee){
print_r($annee[1]); }
}

par Truc » 18 mars 2006, 20:14

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 :wink:

$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 />";

par GoldWel » 18 mars 2006, 18:46

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

par Truc » 18 mars 2006, 14:40

regardes la fonction foreach() il y a des exemples dans la doc, fait quelques tests et reviens si tu n'y arrives pas :wink:

par GoldWel » 18 mars 2006, 14:17

Fodré ke ca m'affiche les données suivantes :

LICENCE 3 mention STIC parcours MIAGE
LICENCE 3 mention STIC parcours Informatique

par GoldWel » 18 mars 2006, 14:15

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"
}
}

par Truc » 18 mars 2006, 14:04

faut renseigner la variable $id_mention avec un id qui est en BD :wink:

par GoldWel » 18 mars 2006, 13:55

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) {
}

par Truc » 18 mars 2006, 13:51

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>

par GoldWel » 18 mars 2006, 12:38

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;

}

par GoldWel » 18 mars 2006, 12:30

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

par Truc » 18 mars 2006, 11:42

la fonction est déja présente dans le fichier où elle est appelée, soit par include soit directement dans la page.

par GoldWel » 18 mars 2006, 11:20

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

par Truc » 18 mars 2006, 11:13

tu inclus le fichier "StructuresFormations.php" puis tu peux appeler la foinction comme ceci:
$tab = array();
$tab = getLesAnnees($id_mention);