Jump to content
Sign in to follow this  
paul5454

affichage requête 2 tables

Rate this topic

Recommended Posts

Bonjour,

J'essaie de faire un trombinoscope de mon assoc mais je cale sur une requête

J'ai deux tables

trombi_name

id_name

nom

trombi_experience

id_experience

id_name

annee

fonction

Ma requête est la suivante

<?
mysql_connect($server, $user, $pass) or die('Erreur de connexion');
mysql_select_db($db) or die('Base inexistante');
$sql = "SELECT trombi_name.id_name, trombi_name.nom, trombi_experience.id_experience, trombi_experience.id_name, trombi_experience.anne, trombi_experience.fonction FROM trombi_name, trombi_experience WHERE trombi_name.id_name=trombi_experience.id_name ORDER BY trombi_name.id_name ";
$result = mysql_query($sql) or die ('Erreur : '.mysql_error() );
while ( $list = mysql_fetch_array( $result ) ) {
echo ' '.$list['id_name'].' / - '.$list['nom'].' - '.$list['anne'].' - '.$list['fonction'].' <br> ';
}
mysql_close();
?>

J'obtiens

NomA - 1999 - pompier

NomA - 1995 - plombier

NomB - 1995 - ambulancier

Mais je voudrais afficher

NomA

- 1999 - pompier

- 1995 - plombier

NomB

1995 - ambulancier

Pourriez-vous m'aider à formuler la requête ?

Merci

Share this post


Link to post
Share on other sites

<?
$query = mysql_query("SELECT nom from trombi_name")or die(mysql_error());
while ($sql=mysql_fetch_array($query)){
$nom[]=$sql['nom'];
}

foreach($nom as $name){
$sql = "SELECT trombi_name.id_name, trombi_name.nom, trombi_experience.id_experience, trombi_experience.id_name, trombi_experience.anne, trombi_experience.fonction FROM trombi_name, trombi_experience WHERE trombi_name.id_name=trombi_experience.id_name and trombi.name = $name ORDER BY trombi_name.id_name ";

$result = mysql_query($sql) or die ('Erreur : '.mysql_error() );
while ( $list = mysql_fetch_array( $result ) ) {
echo ' '.$list['id_name'].' / - '.$list['nom'].' - '.$list['anne'].' - '.$list['fonction'].' <br> ';
}
}

?>

Essaye un truc comme ca ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...