IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Problème avec array [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Août 2005
    Messages : 13
    Points : 8
    Points
    8
    Par défaut Problème avec array
    Bonjour!
    Je me casse la tête depuis quelques jour sur des tableaux en PHP (mon point faible en php).
    Voici le topo:
    -J'ai une bd avec trois table: tb_courrier, tb_groupes, tb_jonctioncour_grp.
    -Je veux afficher dans un tableau sur une même ligne le nom, prenom, courriel (tb_courriel) et les groupes auxquelles chaque courriel sont inscrit (sous forme de checkbox). Le nombre de groupe est dynamique, on peut en rajouter ou en enlever d'ou la nessecité d'une table groupe.
    Voici ma requête MySQl:
    Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    SELECT tb_courriel.id_courriel, 
    	tb_courriel.nom, 
    	tb_courriel.prenom, 
    	tb_courriel.courriel, 
    	tb_mailgrp_courriel.fk_id_mailgrp
    FROM tb_courriel
    LEFT JOIN tb_mailgrp_courriel ON  tb_courriel.id_courriel = tb_mailgrp_courriel.fk_id_courriel
    ORDER BY tb_courriel.courriel ASC
    -Pour chaque ligne de ma requete je creer un objet CourrielComplet que je met dans un tableau d'objet $ArObjCourriel

    -Je me retrouve alors avec certain objet similaire mais ayant un numero de groupe différent (pour ceux inscrit à plusieur groupe ce qui parait logique).

    Comment puis je faire pour trier mon tableau en vue de l'affichage html pour avoir une ligne du style:
    nom prenom courriel groupe1(checkbox) groupe2(checkbox) groupe3(checkbox)
    Mon probleme est vraiment au niveau du trie du $ArObjCourriel!! Je n'arrive pas a séparer les objets ayant un meme courriel mais un id de groupe différent des autres...
    Mes objets sont de la forme: $Courriel->nom, $Courriel->courriel, $Courriel->id_mailgrp ...
    Merci

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Août 2005
    Messages : 13
    Points : 8
    Points
    8
    Par défaut
    Euh pour que ce soit plus simple on peut peut etre directement partir le tri après ma requete, avant même de creer les objets, puisque j'affiche, je peux ma passer des objets pour cette fois et pour la crompréhension:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    $sql = "SELECT tb_courriel.id_courriel, 
    				tb_courriel.nom, 
    				tb_courriel.prenom, 
    				tb_courriel.courriel, 
    				tb_courriel.langue, 
    				tb_mailgrp_courriel.fk_id_mailgrp
    			FROM tb_courriel
    			LEFT JOIN tb_mailgrp_courriel ON  tb_courriel.id_courriel = tb_mailgrp_courriel.fk_id_courriel
    			ORDER BY tb_courriel.courriel ASC";
    $rs = mysql_query($sql)
    				or die ("éxécution de la requête impossible!");
    		$j = 1;
    		while($ligne = mysql_fetch_array($rs,MYSQL_ASSOC))
    			{				
    				foreach($ligne as $nomColonne => $valeur)
    				{
    					$tabcour[$j][$nomColonne] = $valeur;
    				}
    				$j++;
    			}

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2005
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Août 2005
    Messages : 13
    Points : 8
    Points
    8
    Par défaut
    J'ai trouvé après un bon mal de tête...
    Voici la réponse au cas où...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    $tabCourrielComp = CourrielCollection::GetAllWithGrp();
     
    $table_html = '
    <script type="text/javascript" src="inc/tablesort.js"></script>
    <script type="text/javascript" src="inc/tablefilter.js"></script>
    <table id="theTable" cellpadding="0" cellspacing="0" class="sortable-onload-3 rowstyle-alternative no-arrow" >
      <thead>
      <tr>
        <th class="sortable">Nom</th>
        <th class="sortable">Prénom</th>
        <th class="sortable">Courriel</th>';
     
    $tabGroupe = MailGrpCollection::GetAll();
     
    $nbgroup = 0;
    $j=1;
    foreach ($tabGroupe as $grp)
    {
    	$table_html .= '<th class="">'.$grp->GetTitre('fr').'</th>';
    	${"Grp_".$j} = $grp->GetId();
    	$nbgroup++;$j++;
    }
     
    $table_html .= '
      </tr>
      </thead>
     
      <tbody>';
     
    foreach ($tabCourrielComp as $courriel)
    {
    	for ($i=1;$i<=$nbgroup;$i++)
    			{
    				${"check_".$i} = '';
    			}
    	foreach ($tabCourrielComp as $courriel2)
    	{
    		if ($courriel->GetCourriel() == $courriel2->GetCourriel() AND $courriel->GetIdGrpCour() != $courriel2->GetIdGrpCour() AND $courriel->GetCourriel() != null)
    		{
    			for ($i=1;$i<=$nbgroup;$i++)
    			{
    				if (${"Grp_".$i} == $courriel2->GetIdGrpCour()) {${"check_".$i} = 'checked';}
    			}
    			$courriel2->SetCourriel(null);	
    		}		
    	}
    	if ($courriel->GetCourriel() != null)
    	{
    		for ($i=1;$i<=$nbgroup;$i++)
    			{
    				if (${"Grp_".$i} == $courriel->GetIdGrpCour()) {${"check_".$i} = 'checked';}
    			}
    		$table_html .= '
      		<tr>
      			<td>'.$courriel->GetNom().'</td>
        		<td>'.$courriel->GetPrenom().'</td>
        		<td>'.$courriel->GetCourriel().'</td>
      		';
    		for ($i=1;$i<=$nbgroup;$i++)
    			{
    				$table_html .= '<td><input id="check_'.$courriel->GetId().${"Grp_".$i}.'" name="cb" value="'.${"check_".$i}.'" type="checkbox" onclick="changeStatut('.$courriel->GetId().${"Grp_".$i}.','.$courriel->GetId().','.${"Grp_".$i}.')" '.${"check_".$i}.'/></td>';
    			}
    		$table_html .= '</tr>';
    	}
    }
    $table_html .= '
        </tbody>
    </table>
    <script language="javascript">
    setFilterGrid("theTable");
    </script>
    ';

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 24/11/2011, 14h48
  2. problème avec array Notice: Undefined variable:
    Par seksaki dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 10/11/2009, 18h01
  3. Problème avec Array + Form
    Par GoodWear dans le forum Langage
    Réponses: 16
    Dernier message: 22/10/2009, 13h45
  4. [Tableaux] Problème avec array
    Par tremeur53 dans le forum Langage
    Réponses: 9
    Dernier message: 17/01/2009, 00h44
  5. Problème avec array
    Par mariak dans le forum ActionScript 1 & ActionScript 2
    Réponses: 1
    Dernier message: 28/11/2007, 07h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo