Probléme de tableau dans requete sql

Probléme de tableau dans requete sql - PHP - Programmation

Marsh Posté le 22-05-2011 à 12:28:37    

Bonjour à tous,
 
Je suis en train d'écrire une requete sql en php mais avec un tableau, mais je me doute que la syntaxe n'est pas bonne (puisque cela ne marche pas, mais ça fonctionnait sans tableau).
 

Code :
  1. $specia = array("Art de la rue", "Arts numériques","Danse","Chanson","Cinéma","cirque","Musique","Opéra","Performance","Radio","Télévision","Théâtre","Théâtre d'objet","Antiquité","Moyen âge","Renaissance","XVIe","XVIIe","XVIIIe","XIXe","XXe","XXIe" );
  2.  $varia_check = array("cb_uniartsdelarue","cb_uniartsnume","cb_unidanse","cb_unichanson","cb_unicinema","cb_unicirque","cb_unimusique","cb_uniopera","cb_uniperf","cb_uniradio","cb_unitele","cb_unitheatre","cb_unitheatre2","cb_unianti","cb_unimoyen","cb_unirenaiss","cb_unixvie","cb_unixviie","cb_unixviiie","cb_unixixe","cb_unixxe","cb_unixxie" );
  3.  $varia_txt = array("cb_txtartdelarue","cb_txtartsnume","cb_txtdanse","cb_txtchanson","cb_txtcinema","cb_txtcirque","cb_txtmusique","cb_txtopera","cb_txtperformance","cb_txtradio","cb_txttele","cb_txttheatre","cb_txttheatreobj","cb_txtanti","cb_txtmoyenage","cb_txtrenai","cb_txtxvie","cb_txtxviie","cb_txtxviiie","cb_txtxixe","cb_txtxxe","cb_txtxxie" );
  4.  $count = count($specia);
  5.  /*art de la rue si 1*/
  6.  for ($i= 0; $i< $count;$i++) {
  7.  $database->setQuery("UPDATE #__comprofiler SET '$varia_txt[$i]'='$specia[$i]' WHERE '$varia_check[$i]' = 1" );
  8.  $database->query();
  9.  /*art de la rue si 0*/
  10.  $database->setQuery("UPDATE #__comprofiler SET '$varia_txt[$i]'='' WHERE '$varia_check[$i]' = 0" );
  11.  $database->query();
  12.      
  13.  }


 
Donc j'ai 3 tableaux, $spécia c'est le texte que je veux intégrer dans ma bdd, variaç_check ce sont des champs de case à cocher qui sont à 1 ou 0, varia_txt c'est la champs de ma bdd qui doit être remplie par les textes de $specia
donc je compte la longueur de mon 1er tableau (count)
ensuite je fais une boucle pour les Update sql, je me doute que les variables de tableau '$varia_txt[$i]', '$specia[$i]' sont syntaxiquement mal écrit, enfin je crois..
Donc je veux bien un coup de main..
 
merci d'avance
 
Laurent

Reply

Marsh Posté le 22-05-2011 à 12:28:37   

Reply

Marsh Posté le 22-05-2011 à 12:42:13    

Bon ben j'ai trouvé..
 
 

Code :
  1. $specia = array("Art de la rue", "Arts numériques","Danse","Chanson","Cinéma","cirque","Musique","Opéra","Performance","Radio","Télévision","Théâtre","Théâtre d'objet","Antiquité","Moyen âge","Renaissance","XVIe","XVIIe","XVIIIe","XIXe","XXe","XXIe" );
  2.  $varia_check = array("cb_uniartsdelarue","cb_uniartsnume","cb_unidanse","cb_unichanson","cb_unicinema","cb_unicirque","cb_unimusique","cb_uniopera","cb_uniperf","cb_uniradio","cb_unitele","cb_unitheatre","cb_unitheatre2","cb_unianti","cb_unimoyen","cb_unirenaiss","cb_unixvie","cb_unixviie","cb_unixviiie","cb_unixixe","cb_unixxe","cb_unixxie" );
  3.  $varia_txt = array("cb_txtartdelarue","cb_txtartsnume","cb_txtdanse","cb_txtchanson","cb_txtcinema","cb_txtcirque","cb_txtmusique","cb_txtopera","cb_txtperformance","cb_txtradio","cb_txttele","cb_txttheatre","cb_txttheatreobj","cb_txtanti","cb_txtmoyenage","cb_txtrenai","cb_txtxvie","cb_txtxviie","cb_txtxviiie","cb_txtxixe","cb_txtxxe","cb_txtxxie" );
  4.  $count = count($specia);
  5.  /*art de la rue si 1*/
  6.  for ($i= 0; $i< $count;$i++) {
  7.  $database->setQuery("UPDATE #__comprofiler SET $varia_txt[$i]='$specia[$i]' WHERE $varia_check[$i] = 1" );
  8.  $database->query();
  9.  /*art de la rue si 0*/
  10.  $database->setQuery("UPDATE #__comprofiler SET $varia_txt[$i]='' WHERE $varia_check[$i] = 0" );
  11.  $database->query();
  12.      
  13.  }


 
donc juste des simples quotes à mettre pour mon tableau $specia[]..
 
Si ça peu servir...

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed