Affiche les resutats de mes requètes

Résolu
je suis la encore . je voulais pousser un peu plus mais voila que je bloque .
les codes ci-dessus concernait une seule table victime(matricule,questionnaire,nom,region,village,tel)
mais j'ai une autre table enfant(id_enfant,questionnaire,nom1,lien1,sexe1,age1)
alors je voudrais aussi afficher les nom des enfants et quelques informations concernant les enfants.
voici l'erreur qui s'affiche :
Erreur serveur
Le site Web a rencontré une erreur lors de l'extraction de http://localhost/INSCRIPTION/test_Recherche2.php. Cela peut être dû à une opération de maintenance ou à une configuration incorrecte.

voici le code :
<?php
if(isset($_POST['questionnaire']) && !empty($_POST['questionnaire'])){
 include("connection.php");
$id=(int)$_POST['questionnaire'];
$id=mysql_real_escape_string($id);
$sql = "SELECT DISTINCT questionnaire,nom,region,village,tel FROM victime where questionnaire='".$id."'";
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
}
?> 




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
<style type="text/css">
<!--
.Style3 {color: #FFFFFF}
.Style6 {
	color: #0000FF;
	font-style: italic;
	font-weight: bold;
}
.Style11 {color: #0000FF; font-weight: bold; }
.Style14 {color: #990000}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="333" border="0" align="center" bgcolor="#FFFFCC">
    <tr>
      <td bgcolor="#FF00FF"><A HREF="enregistrement.php" TITLE="click pour enregistrer vos enfants!!!  !!!!" class="Style17 Style3"><strong>Accueil</strong></a></td>
      <td bgcolor="#FF00FF">&nbsp;</td>
    </tr>
    <tr>
      <td width="195">Numero du Questionnaire
        <input type="text" name="questionnaire" /></td>
		
      <td width="128"><input type="submit" name="Submit" value="RECHERCHER" /></td>
    </tr>
  </table>
</form>

<div align="center">
  <h1 align="center" class="Style6">&nbsp;</h1>
</div>
<p>&nbsp;</p><center>
<fieldset style="width: 650px;" ><legend><span class="Style11">CHEF DE MENAGE</span></legend>
<table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
  <tr bgcolor="#999999">
    <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
    <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
  </tr>
  <tr bgcolor="#999999">
    <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
    <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">REGION </span></th>
    <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">VILLAGE </span></th>
    <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">TEL </span></th>
  </tr>
  <?php
  		while ($liste_etu=mysql_fetch_assoc($req)) {
			$j=$i%2;
		
  ?>
  <tr bgcolor=#FFFFCC>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['region'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['village'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['tel'] ?>"/></td>
  </tr>
  <?php
  }
  ?>
</table>
</fieldset>
</center>
</p><center>
<fieldset style="width: 650px;" ><legend><span class="Style11">MEMBRES</span></legend>
<table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
  <tr bgcolor="#999999">
    <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
    <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
  </tr>
  <tr bgcolor="#999999">
    <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
    <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">LIEN </span></th>
    <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">SEXE </span></th>
    <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">AGE </span></th>
  </tr>
  <?php
  if(isset($_POST['matricule']) && !empty($_POST['matricule'])){
  $id=(int)$_POST['matricule'];
$id=mysql_real_escape_string($id);
$sql = "SELECT DISTINCT matricule,nom1,lien1,sexe1,age1 FROM enfant where matricule='".$questionnaire."'";
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
  		while ($liste_etu=mysql_fetch_assoc($req)) {
			$j=$i%2;
		
  ?>
  <tr bgcolor=#FFFFCC>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom1'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['lien1'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['sexe1'] ?>"/></td>
    <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['age1'] ?>"/></td>
  </tr>
  <?php
  }
  }
  ?>
</table>
</fieldset>
</center>
</body>
</html>

8 réponses

  1. Salut,

    C'est pas plutôt intval($_POST['questionnaire']) que (int) ?
    0
    1. le premier tableau affiche sans problème mais le 2ième apparait sans rien afficher
      0
      1. mais j'ai une autre table enfant(id_enfant,questionnaire,nom1,lien1,sexe1,age1)

        et ta requete:

        $sql = "SELECT DISTINCT matricule,nom1,lien1,sexe1,age1 FROM enfant where matricule='"...

        il n'y a pas de champ matricule dans ta table enfant
        0
        1. j'ai continué a chercher et maintenant le deuxième tableau s'affiche mais affiche tous les enfants or moi je veux qu'il affiche que les enfants de la victime dont le numéro (questionnaire ) a été entré :
          voici le code modifié :
          
          
          <?php
          if(isset($_POST['questionnaire']) && !empty($_POST['questionnaire'])){
           include("connection.php");
          $id=(int)$_POST['questionnaire'];
          $id=mysql_real_escape_string($id);
          $sql = "SELECT DISTINCT questionnaire,nom,region,village,tel FROM victime where questionnaire='".$id."'";
          $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
          }
          ?> 
          
          
          
          
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>Document sans titre</title>
          <style type="text/css">
          <!--
          .Style3 {color: #FFFFFF}
          .Style6 {
          	color: #0000FF;
          	font-style: italic;
          	font-weight: bold;
          }
          .Style11 {color: #0000FF; font-weight: bold; }
          .Style14 {color: #990000}
          -->
          </style>
          </head>
          
          <body>
          <form id="form1" name="form1" method="post" action="">
            <table width="333" border="0" align="center" bgcolor="#FFFFCC">
              <tr>
                <td bgcolor="#FF00FF"><A HREF="enregistrement.php" TITLE="click pour enregistrer vos enfants!!!  !!!!" class="Style17 Style3"><strong>Accueil</strong></a></td>
                <td bgcolor="#FF00FF">&nbsp;</td>
              </tr>
              <tr>
                <td width="195">Numero du Questionnaire
                  <input type="text" name="questionnaire" /></td>
          		
                <td width="128"><input type="submit" name="Submit" value="RECHERCHER" /></td>
              </tr>
            </table>
          </form>
          
          <div align="center">
            <h1 align="center" class="Style6">&nbsp;</h1>
          </div>
          <p>&nbsp;</p><center>
          <fieldset style="width: 650px;" ><legend><span class="Style11">CHEF DE MENAGE</span></legend>
          <table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
            <tr bgcolor="#999999">
              <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
              <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
            </tr>
            <tr bgcolor="#999999">
              <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
              <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">REGION </span></th>
              <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">VILLAGE </span></th>
              <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">TEL </span></th>
            </tr>
            <?php
            		while ($liste_etu=mysql_fetch_assoc($req)) {
          			$j=$i%2;
          		
            ?>
            <tr bgcolor=#FFFFCC>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['region'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['village'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['tel'] ?>"/></td>
            </tr>
            <?php
            }
            ?>
          </table>
          </fieldset>
          </center>
          </p><center>
          <fieldset style="width: 650px;" ><legend><span class="Style11">MEMBRES</span></legend>
          <table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
            <tr bgcolor="#999999">
              <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
              <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
            </tr>
            <tr bgcolor="#999999">
              <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
              <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">LIEN </span></th>
              <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">SEXE </span></th>
              <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">AGE </span></th>
            </tr>
            <?php
            //if(isset($_POST['matricule']) && !empty($_POST['matricule']) ){
               if(isset($_POST['questionnaire']) && !empty($_POST['questionnaire']) ){
                         $id=(int)$_POST['questionnaire'];
                         $id=mysql_real_escape_string($id);
                         $id1=(int)$_POST['matricule'];
                         $id1=mysql_real_escape_string($id);
                         $sql = "SELECT DISTINCT a.nom1,a.lien1,a.sexe1,a.age1 FROM enfant a ,victime b where $id='".$id1."'";
                         $req = mysql_query($sql) or die(a.'Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
            		             while ($liste_etu=mysql_fetch_assoc($req)) {
          		             	$j=$i%2;
          		
            ?>
            <tr bgcolor=#FFFFCC>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom1'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['lien1'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['sexe1'] ?>"/></td>
              <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['age1'] ?>"/></td>
            </tr>
            <?php
              // }
              }
            }
            ?>
          </table>
          </fieldset>
          </center>
          </body>
          </html>
          
          
          0
          1. un peu d'attention:

            $sql = "SELECT DISTINCT a.nom1,a.lien1,a.sexe1,a.age1 FROM enfant a ,victime b where $id='".$id1."'";

            $sql = "SELECT DISTINCT a.nom1,a.lien1,a.sexe1,a.age1 FROM enfant a ,victime b where matricule='".$id1."'";


            et puis la:

            $id=(int)$_POST['questionnaire'];
            $id=mysql_real_escape_string($id);
            $id1=(int)$_POST['matricule'];
            $id1=mysql_real_escape_string($id);

            je ne comprend pas ?
            0
            1. au fait je suis débutant donc je bricole .
              j'ai deux tables non liées :
              victime (id_victime,questionnaire,nom,region,village,tel)
              enfant(id_enfant,matricule,nom1,lien1,sexe1,age1)
              matricule me permet de retrouver les enfants de la victime
              dc questionnaire(int) est égal à matricule(int)

              mon objectif est d'afficher les informations (nom,region,village,tel) de le victime et de ses enfants (nom1,lien1,sexe1,age1) dans deux tableau différents
              0
              1. alors pour la 2 ième req essayes:

                $sql = "SELECT * FROM enfant  WHERE matricule='".$id."'";
                0
                1. oui merci ça marche tres bien. vraiment merci .
                  voici le code final :
                  
                  
                  <?php
                  if(isset($_POST['questionnaire']) && !empty($_POST['questionnaire'])){
                   include("connection.php");
                  $id=(int)$_POST['questionnaire'];
                  $id=mysql_real_escape_string($id);
                  $sql = "SELECT DISTINCT questionnaire,nom,region,village,tel FROM victime where questionnaire='".$id."'";
                  $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
                  }
                  ?> 
                  
                  
                  
                  
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                  <title>Document sans titre</title>
                  <style type="text/css">
                  <!--
                  .Style3 {color: #FFFFFF}
                  .Style6 {
                  	color: #0000FF;
                  	font-style: italic;
                  	font-weight: bold;
                  }
                  .Style11 {color: #0000FF; font-weight: bold; }
                  .Style14 {color: #990000}
                  -->
                  </style>
                  </head>
                  
                  <body>
                  <form id="form1" name="form1" method="post" action="">
                    <table width="333" border="0" align="center" bgcolor="#FFFFCC">
                      <tr>
                        <td bgcolor="#FF00FF"><A HREF="enregistrement.php" TITLE="click pour enregistrer vos enfants!!!  !!!!" class="Style17 Style3"><strong>Accueil</strong></a></td>
                        <td bgcolor="#FF00FF">&nbsp;</td>
                      </tr>
                      <tr>
                        <td width="195">Numero du Questionnaire
                          <input type="text" name="questionnaire" /></td>
                  		
                        <td width="128"><input type="submit" name="Submit" value="RECHERCHER" /></td>
                      </tr>
                    </table>
                  </form>
                  
                  <div align="center">
                    <h1 align="center" class="Style6">&nbsp;</h1>
                  </div>
                  <p>&nbsp;</p><center>
                  <fieldset style="width: 650px;" ><legend><span class="Style11">CHEF DE MENAGE</span></legend>
                  <table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
                    <tr bgcolor="#999999">
                      <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
                      <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
                    </tr>
                    <tr bgcolor="#999999">
                      <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
                      <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">REGION </span></th>
                      <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">VILLAGE </span></th>
                      <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">TEL </span></th>
                    </tr>
                    <?php
                    		while ($liste_etu=mysql_fetch_assoc($req)) {
                  			$j=$i%2;
                  		
                    ?>
                    <tr bgcolor=#FFFFCC>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['region'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['village'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['tel'] ?>"/></td>
                    </tr>
                    <?php
                    }
                    ?>
                  </table>
                  </fieldset>
                  </center>
                  </p><center>
                  <fieldset style="width: 650px;" ><legend><span class="Style11">MEMBRES</span></legend>
                  <table width="585" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
                    <tr bgcolor="#999999">
                      <th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
                      <td width="103" bgcolor="#FFFFCC"><div align="right"></div></td>
                    </tr>
                    <tr bgcolor="#999999">
                      <th width="256" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
                      <th width="103" bgcolor="#FFFFCC" scope="row"><span class="Style14">LIEN </span></th>
                      <th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">SEXE </span></th>
                      <th width="84" bgcolor="#FFFFCC" scope="row"><span class="Style14">AGE </span></th>
                    </tr>
                    <?php
                    //if(isset($_POST['matricule']) && !empty($_POST['matricule']) ){
                       if(isset($_POST['questionnaire']) && !empty($_POST['questionnaire']) ){
                                 $id=(int)$_POST['questionnaire'];
                                $id=mysql_real_escape_string($id);
                  			// if($req){ 
                                 $id1=(int)$_POST['matricule'];
                                 $id1=mysql_real_escape_string($id1);
                                 $sql =  "SELECT * FROM enfant  WHERE matricule='".$id."'  ";
                                 $req = mysql_query($sql) or die(a.'Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
                    		             while ($liste_etu=mysql_fetch_assoc($req)) {
                  		             	$j=$i%2;
                  		
                    ?>
                    <tr bgcolor=#FFFFCC>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['nom1'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['lien1'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['sexe1'] ?>"/></td>
                      <td bgcolor="#CCCCCC"><input type="text" name="textfield" value="<?php echo $liste_etu['age1'] ?>"/></td>
                    </tr>
                    <?php
                      // }
                      }
                    }
                    ?>
                  </table>
                  </fieldset>
                  </center>
                  </body>
                  </html>
                  
                  
                  0