Boucle ? ou pas Boucle ?

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 : Boucle ? ou pas Boucle ?

par Truc » 05 févr. 2006, 18:56

enfaite tu boucles déja sur les cases or c'est ce qu'il faut éviter pour ne pas avoir des cases en double.

Donc tu boucles uniquement sur la récupération des id et non sur les cases.
Ces id tu peux les stocker dans un tableau puis lors de la construcion des cases verifier si l'id qui correspond a la case est dans ce tableau.
<?php

if ($resselectdid = mysql_query($sqldid))
{
    $tab=array();
    while($selectdid = mysql_fetch_array($resselectdid))
    { 
         $tab[] = $selectdid['garanties'];
    }   
    // lignes a adapter pour les autres cases 
    $checked = (in_array(3,$tab)) ? "checked=\"checked\"" : ""  ?>
    <td>
        <input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="3" <?php echo $checked; ?>>
    </td>
    ...
    ...
<?
}
tu peux te baser sur le même système pour les autres cases

par Dom! » 05 févr. 2006, 18:49

Ha j'ai compris ce que tu m'a écrit LOL aprés avoir bien lu !

Si par exemple j'ai dix enregistrements avec le meme N° de contrat j'aurais donc 10 fois mes cases à cocher....

Mais alors comment faire pour réctifier cela ?

par Dom! » 05 févr. 2006, 18:35

$selectdid['garanties'] contient un entier

Ensuite oui j'a plusieur numero de contrat . Mais je ne trouve toujours sia spas comment faire en sorte à régler le soucis.... Ou est ce qu'il faut que je boucle ? :roll:

merci

par Truc » 05 févr. 2006, 18:32

que contient $selectdid['garanties'] ? un entier ?

ensuite si tu as toutes les cases en triple c'est parce que tu boucles sur le résultat de la requete.

Etant donné que tu effectue un choix sur le numéro de contrat (d'apres la requete) tu dois avoir plusieurs contrats avec le même numéro :?

par Dom! » 05 févr. 2006, 14:47

Bon j'ai revu mon code ! le probleme c'est que j'ai toutes mes cases à cocher en triple :shock: je ne comprend pas pourquoi ?

  <p class="win_blue_text">Veuillez selectionner les garanties pour le contrat numéro <?php echo $_GET['numero_contrat']; ?>
  <form action="" method=post name="form1" id="form1">

  <table wid>
    <table width="411" border="0" align="center" class="win_blue">
          <tr>
    <table width="411" border="0" align="center" class="win_blue">
      <tr>
	  <?php 
$test = $_GET['numero_contrat']; 
$sqldid = "select id, num_contrat, garanties from garanties where num_contrat = '". $test ."'"; 
// $nbsql += 1; 
if ($resselectdid = mysql_query($sqldid)) 
{ 
    while($selectdid = mysql_fetch_array($resselectdid))
    { 
        echo "La valeur \$test = [". $test ."] et \$selectdid[\"garanties\"] = ". $selectdid['garanties'] ."<br />\n"; 
?>
		<td><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="3" <?php if ($selectdid["garanties"] == 3) {echo "checked=\"checked\"";} ?> ></td>		
        
        <td class="win_blue_text">RESPONSABILITE CIVILE</td>
					
        <td></td>
      </tr>
      <tr>
        <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="9" <?php if ($selectdid["garanties"] == 9) {echo "checked=\"checked\"";} ?> ></td>
	
          <td class="win_blue_text">DEFENSE / RECOURS</td>
	  
        <td width="100"><label></label>
          </label>
          <label>
          </label></td>
        </tr>
            
              <tr>
                        
                 <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="2" <?php if ($selectdid["garanties"] == 2) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">ASSISTANCE</td>
                <td><select name="franchises[2]" id="franchises[2]">
                    <option value="00 Kms">00 Kms</option>
                    <option value="30 Kms">30 Kms</option>
                    <option value="50 Kms">50 Kms</option>
                </select></td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="10" <?php if ($selectdid["garanties"] == 10) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">ASSURANCE DU CONDUCTEUR</td>
                <td><label></label></td>
              </tr>
              <tr>
                <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="7" <?php if ($selectdid["garanties"] == 7) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">INCENDIE
                  <label></label></td>
                <td><input name='franchises[7]' type=text class="win_blue_text" id="franchises[7]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro </span></td>
              </tr>
              <tr>
                <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="6" <?php if ($selectdid["garanties"] == 6) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">VOL / VANDALISME</td>
                <td><input name='franchises[6]' type=text class="win_blue_text" id="franchises[6]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="8" <?php if ($selectdid["garanties"] == 8) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">BRIS DE GLACE</td>
                <td><input name='franchises[8]' type=text class="win_blue_text" id="franchises[8]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="5" <?php if ($selectdid["garanties"] == 5) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">DOMMAGES COLLISION</td>
                <td><span class="win_blue_text Style1">
                  <input name='franchises[5]' type=text class="win_blue_text" id="franchises[5]" value="0" size="8">
                  &euro;uro</span></td>
              </tr>
              <tr>
                <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="4" <?php if ($selectdid["garanties"] == 4) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">DOMMAGES TOUS ACCIDENTS</td>
                <td><input name='franchises[4]' type=text class="win_blue_text" id="franchises[4]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="11" <?php if ($selectdid["garanties"] == 11) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">ACCESSOIRES</td>
                <td><input name='franchises[11]' type=text class="win_blue_text" id="franchises[11]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
                <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="12" <?php if ($selectdid["garanties"] == 12) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">EFFETS / OBJETS PERSONNELS</td>
                <td><input name='franchises[12]' type=text class="win_blue_text" id="franchises[12]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
                <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="17" <?php if ($selectdid["garanties"] == 17) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">APPAREIL RADIO </td>
                <td><input name='franchises[17]' type=text class="win_blue_text" id="franchises[17]" value="0" size="8">
                    <span class="win_blue_text Style1">&euro;uro</span></td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="18" <?php if ($selectdid["garanties"] == 18) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">CREDIT BAIL</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
               <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="13" <?php if ($selectdid["garanties"] == 13) {echo "checked=\"checked\"";} ?> ></td>
                <td class="win_blue_text">PROTECTION JURIDIQUE</td>
				<?php
							} 
} 
		?>

                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="3"><label></label>
                    <label>
                    <input name="numero" type="hidden" id="numero" value="<?php echo $_GET['numclient']; ?>">
                    <input name="numero_contrat" type="hidden" id="numero_contrat" value="<?php echo $_GET['numero_contrat']; ?>">
                  </label></td>
              </tr>
              <tr>
                <td colspan="3"><div align="center">
                    <input name='valider' type=submit class="win_blue_titre" value='Valider les garanties'>
                </div></td>
              </tr>
            </table>
			
    <tr>
              <p>
              <a href="javascript:history.go(-1);"><-- Retour</a></p>
    </form>
Aidez moi s'il vous plaiiiiiit merciiiiiiiiii :wink:

par Dom! » 05 févr. 2006, 14:29

BOnjour à tous !


Quelqun pourrait il me dire pourquoi mes cases ne se coche pas quand garanties est dans ma base ??
	  <?php 
$test = $_GET['numero_contrat']; 
$sqldid = "select id, num_contrat, garanties from garanties where num_contrat = '". $test ."'"; 
// $nbsql += 1; 
if ($resselectdid = mysql_query($sqldid)) 
{ 
    while($selectdid = mysql_fetch_array($resselectdid))
    { 
        echo "La valeur \$test = [". $test ."] et \$selectdid[\"garanties\"] = ". $selectdid['garanties'] ."<br />\n"; 
			} 
} 
		?>
		<td><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="3" <?php if ($selectdid["garanties"] == 3) {echo "checked=\"checked\"";} ?> ></td>		
        
        <td class="win_blue_text">RESPONSABILITE CIVILE</td>
					
        <td></td>
      </tr>
      <tr>
        <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value="9" <?php if ($selectdid["garanties"] == 9) {echo "checked=\"checked\"";} ?> ></td>
	
          <td class="win_blue_text">DEFENSE / RECOURS</td>
	  
        <td width="100"><label></label>
          </label>
          <label>
          </label></td>
        </tr>
            
              <tr>
                        
                 <td width="27"><input name="id_garanties[]" type="checkbox" id="id_garanties[]" value='2' <?php $checked = ($selectdid['garanties']==2) ? "checked='checked'" : ""; echo $checked;?>  /></td> 
                <td class="win_blue_text">ASSISTANCE</td>
                <td><select name="franchises[2]" id="franchises[2]">
                    <option value="00 Kms">00 Kms</option>
                    <option value="30 Kms">30 Kms</option>
                    <option value="50 Kms">50 Kms</option>
                </select></td>
</table>
Merci pour votre aide

par Truc » 05 févr. 2006, 01:22

essaie avec:
<td width="27"><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="3" <?php $checked = ($selectdid['garanties']==3) ? "checked='checked'" : ""; echo $checked;?>  /></td>
une parenthèse de trop

par Dom! » 05 févr. 2006, 01:12

Oups c'est vrai pardon pardon
 <td width="27"><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="3" <?php echo ($selectdid['garanties']==3) ? checked="checked" : ""); ?> /></td> 

C'est cette ligne :D [/php]

par Truc » 05 févr. 2006, 01:09

Tu sais qu'il y a eu plusieurs propositions et chacune contient un = et il n'y a pas 356 lignes visibles ici.

Comment veux tu qu'on sache d'où le problème peut venir ? :shock:

par Dom! » 05 févr. 2006, 01:03

J'ai une erreur :

Parse error: parse error, unexpected '=' in /var/www/html/Intranet/garanties.php on line 356

J'ai pourtant fait comme vous m'aviez di....

par albat » 04 févr. 2006, 17:14

Lorsque le resultat d'un test if se limite à une instruction, les accolades sont facultatives
Cependant, il est préférable d'en mettre en toutes circonstances.

Dans le cas qui nous préoccupe, leur absence ne déclenche pas d'erreur.

par Tictac » 04 févr. 2006, 16:09

je comprend meme pas que tu aies pas un message d'erreur , tu as oublié de mettre les {} de ton if
<td width="27"></span><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="9" <? if ($selectdid["garanties"] == 9) print "checked"; ?> ></td>

<!--devient -->

<td width="27"></span><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="9" <? if ($selectdid["garanties"] == 9) {echo "checked"}; ?> ></td>
le mieux est d'utiliser l'opérateur ternaire comme l'a fait albat

++

par albat » 04 févr. 2006, 15:07

Ceci fonctionne-t-il mieux ?
<td width="27"><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="9" <?php echo ($selectdid['garanties']==9) ? checked="checked" : ""); ?> /></td>
<td width="27"></span> : écriture illicite
<? : à remplacer par <?php
"checked" : à remplacer par checked="checked"

par Dom! » 04 févr. 2006, 14:32

Je réouvre ce post car je mets ce code pour cocher ma case mais ca ne fonctionne pas ! je ne comprend pas pourquoi ! merci pour votre aide.
  <td width="27"></span><input name="id_garanties[]" type="checkbox" class="champ" id="id_garanties[]" value="9" <? if ($selectdid["garanties"] == 9) print "checked"; ?> ></td>

par Dom! » 04 févr. 2006, 13:26

C'est tout simplement parfait :lol: merci