Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/05/2011, 14h51   #1
Futur Membre du Club
 
Homme
Développeur Web
Inscription : novembre 2007
Messages : 185
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : novembre 2007
Messages : 185
Points : 15
Points : 15
Par défaut Création dynamique de champs dans une table

Bonjour à tous,

Je voudais créer dynamiquement des champs dans une table.
Pour cela j'ai inseré une boucle while dans une requête creation de table mais j'ai une erreur de syntaxe.
Je me pose la question de savoir si ce que je ve faire est possible

Ma requête :
Code :
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
 
$creation_table=mysql_query("CREATE TABLE IF NOT EXISTS `parc_option_test` (
  `code_groupe` text NOT NULL,
  `code_entreprise` text NOT NULL,
  `compte_client` text NOT NULL,
  `nom_abonne` text NOT NULL,
  `utilisateur` text NOT NULL,
  `reference` text NOT NULL,
  `gsm` text NOT NULL,
  `num_sim` text NOT NULL,
  `num_sim_jumelle` text NOT NULL,
  `num_gsn_carte_jumelle` text NOT NULL,
  `num_fax` text NOT NULL,
  `num_data` text NOT NULL,
  `num_imei` text NOT NULL,
  `code_tarif` text NOT NULL,
  `code_package` text NOT NULL,
  `date_connexion` date NOT NULL,
  `date_engagement` date NOT NULL,
  `duree_contrat` text NOT NULL,
  ". while ($uneligne=odbc_fetch_array($rq_cpt)) 
		{  
		echo"`".$uneligne[0]."` text NOT NULL," ;
		} ." 
  `date_deconnexion` date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
Mon Message d'erreur :
Code :
1
2
 
Parse error: syntax error, unexpected T_WHILE in
Merci d'avance pour vos réponse
kamnouz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2011, 10h51   #2
Invité régulier
 
Homme
Développeur Web
Inscription : mai 2011
Messages : 24
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : mai 2011
Messages : 24
Points : 8
Points : 8
Bonjour,

Je te propose une piste à creuser, sans être sur de mon coup.

Code :
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
 
// On mets le resultat dans une variable pour faciliter l'ecriture de la requete
while ($uneligne=odbc_fetch_array($rq_cpt)) 
{  
$newLigne = $uneligne[0]  ;
} 
 
$creation_table = "CREATE TABLE IF NOT EXISTS `parc_option_test` (
  `code_groupe` text NOT NULL,
  `code_entreprise` text NOT NULL,
  `compte_client` text NOT NULL,
  `nom_abonne` text NOT NULL,
  `utilisateur` text NOT NULL,
  `reference` text NOT NULL,
  `gsm` text NOT NULL,
  `num_sim` text NOT NULL,
  `num_sim_jumelle` text NOT NULL,
  `num_gsn_carte_jumelle` text NOT NULL,
  `num_fax` text NOT NULL,
  `num_data` text NOT NULL,
  `num_imei` text NOT NULL,
  `code_tarif` text NOT NULL,
  `code_package` text NOT NULL,
  `date_connexion` date NOT NULL,
  `date_engagement` date NOT NULL,
  `duree_contrat` text NOT NULL,
  `$newLigne` text NOT NULL,
  `date_deconnexion` date NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1";
 
 mysql_query($creation_table);
Je prends cela comme un exercice, j'éspère que quelqu'un de plus experimenté te viendra en aide.
Code85 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2011, 11h09   #3
Membre éprouvé
 
Avatar de Nheo_
 
Homme
Étudiant
Inscription : avril 2011
Messages : 317
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2011
Messages : 317
Points : 405
Points : 405
Bonjour,

Voici une solution :

Code :
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
$requete = "CREATE TABLE IF NOT EXISTS `parc_option_test` (
  `code_groupe` text NOT NULL,
  `code_entreprise` text NOT NULL,
  `compte_client` text NOT NULL,
  `nom_abonne` text NOT NULL,
  `utilisateur` text NOT NULL,
  `reference` text NOT NULL,
  `gsm` text NOT NULL,
  `num_sim` text NOT NULL,
  `num_sim_jumelle` text NOT NULL,
  `num_gsn_carte_jumelle` text NOT NULL,
  `num_fax` text NOT NULL,
  `num_data` text NOT NULL,
  `num_imei` text NOT NULL,
  `code_tarif` text NOT NULL,
  `code_package` text NOT NULL,
  `date_connexion` date NOT NULL,
  `date_engagement` date NOT NULL,
  `duree_contrat` text NOT NULL,";
 
while ($uneligne=odbc_fetch_array($rq_cpt)) 
{  
     $requete.= "`".$uneligne[0]."` text NOT NULL," ;
}
 
$requete .= "`date_deconnexion` date NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
 
$creation_table=mysql_query($requete);
Nheo_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h21.


 
 
 
 
Partenaires

Hébergement Web