Bonjour à tous;

Je souhaite que je peux trouver une solution à mon problème avec cette boucle!

voila ma base de données:

Code sql : 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- <a href="http://www.phpmyadmin.net" target="_blank">http://www.phpmyadmin.net</a>
--
-- Serveur: localhost
-- Généré le : Mar 22 Octobre 2013 à 12:46
-- Version du serveur: 5.5.8
-- Version de PHP: 5.3.5
 
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
 
--
-- Base de données: `contact_form1`
--
 
-- --------------------------------------------------------
 
--
-- Structure de la table `connexion`
--
 
CREATE TABLE IF NOT EXISTS `connexion` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `ref_id_user` int(10) NOT NULL DEFAULT '0',
  `date_connex` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `date_cnx` date NOT NULL,
  `adresse_ip_connex` varchar(15) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;
 
--
-- Contenu de la table `connexion`
--
 
INSERT INTO `connexion` (`id`, `ref_id_user`, `date_connex`, `date_cnx`, `adresse_ip_connex`) VALUES
(8, 1, '2013-10-17 13:06:15', '2013-10-17', '127.0.0.1'),
(7, 1, '2013-10-17 13:04:43', '2013-10-17', '127.0.0.1'),
(6, 1, '2013-10-17 13:04:06', '2013-10-17', '127.0.0.1'),
(5, 1, '2013-10-17 12:53:04', '2013-10-17', '127.0.0.1'),
(9, 1, '2013-10-17 13:06:54', '2013-10-17', '127.0.0.1'),
(10, 1, '2013-10-17 13:09:34', '2013-10-17', '127.0.0.1'),
(11, 1, '2013-10-17 13:10:32', '2013-10-17', '127.0.0.1'),
(12, 1, '2013-10-17 13:12:48', '2013-10-17', '127.0.0.1'),
(13, 1, '2013-10-17 13:43:51', '2013-10-17', '127.0.0.1'),
(14, 1, '2013-10-17 14:09:57', '2013-10-17', '127.0.0.1'),
(15, 1, '2013-10-17 14:24:43', '2013-10-17', '127.0.0.1'),
(16, 1, '2013-10-17 14:30:04', '2013-10-17', '127.0.0.1'),
(17, 1, '2013-10-17 15:10:24', '2013-10-17', '127.0.0.1'),
(18, 1, '2013-10-18 00:22:29', '2013-10-18', '127.0.0.1'),
(19, 1, '2013-10-18 00:24:58', '2013-10-18', '127.0.0.1'),
(20, 1, '2013-10-18 00:26:46', '2013-10-18', '127.0.0.1'),
(21, 3, '2013-10-18 00:37:04', '2013-10-18', '127.0.0.1'),
(22, 3, '2013-10-18 00:37:45', '2013-10-18', '127.0.0.1');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `contact`
--
 
CREATE TABLE IF NOT EXISTS `contact` (
  `id_contact` int(11) NOT NULL AUTO_INCREMENT,
  `cin` text NOT NULL,
  `nom` text NOT NULL,
  `prenom` text NOT NULL,
  `email` text NOT NULL,
  `telephone` text NOT NULL,
  `departement` text NOT NULL,
  `taches` text NOT NULL,
  PRIMARY KEY (`id_contact`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
--
-- Contenu de la table `contact`
--
 
 
-- --------------------------------------------------------
 
--
-- Structure de la table `horaire`
--
 
CREATE TABLE IF NOT EXISTS `horaire` (
  `id_horaire` int(11) NOT NULL AUTO_INCREMENT,
  `horaire` varchar(100) NOT NULL,
  PRIMARY KEY (`id_horaire`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
 
--
-- Contenu de la table `horaire`
--
 
INSERT INTO `horaire` (`id_horaire`, `horaire`) VALUES
(1, '08:00-16:30'),
(2, '08:00-18:30'),
(3, '18:30-03:00'),
(4, '22:00-05:00'),
(5, 'Repos');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `jours`
--
 
CREATE TABLE IF NOT EXISTS `jours` (
  `id_jour` int(11) NOT NULL AUTO_INCREMENT,
  `jour` varchar(60) NOT NULL,
  PRIMARY KEY (`id_jour`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
 
--
-- Contenu de la table `jours`
--
 
INSERT INTO `jours` (`id_jour`, `jour`) VALUES
(1, 'Lundi'),
(2, 'Mardi'),
(3, 'Mercredi'),
(4, 'Jeudi'),
(5, 'Vendredi'),
(6, 'Samedi'),
(7, 'Dimanche ');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `semaine`
--
 
CREATE TABLE IF NOT EXISTS `semaine` (
  `id_semaine` int(11) NOT NULL AUTO_INCREMENT,
  `semaine` varchar(50) NOT NULL,
  PRIMARY KEY (`id_semaine`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
 
--
-- Contenu de la table `semaine`
--
 
INSERT INTO `semaine` (`id_semaine`, `semaine`) VALUES
(1, 'Semaine 1'),
(2, 'Semaine 2');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `semaine_jour_horaire`
--
 
CREATE TABLE IF NOT EXISTS `semaine_jour_horaire` (
  `id_horaire_jour_semaine` int(11) NOT NULL AUTO_INCREMENT,
  `id_semaine` int(11) NOT NULL,
  `id_jour` int(11) NOT NULL,
  `id_horaire` int(11) NOT NULL,
  `id_contact` int(11) NOT NULL,
  PRIMARY KEY (`id_horaire_jour_semaine`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
--
-- Contenu de la table `semaine_jour_horaire`
--
 
 
-- --------------------------------------------------------
 
--
-- Structure de la table `utilisateurs`
--
 
CREATE TABLE IF NOT EXISTS `utilisateurs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_contact` int(11) NOT NULL,
  `email` text NOT NULL,
  `pass` text NOT NULL,
  `privilege` text NOT NULL,
  `date_ouverture` date NOT NULL,
  `statuts` int(11) NOT NULL,
  `clef` text NOT NULL,
  `line_compte` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
 
--
-- Contenu de la table `utilisateurs`
--
 
INSERT INTO `utilisateurs` (`id`, `id_contact`, `email`, `pass`, `privilege`, `date_ouverture`, `statuts`, `clef`, `line_compte`) VALUES
(3, 9, 'taoufik.rai@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'super_admin', '2013-10-17', 0, '4b8fd3f079e7f86de2eb88ff847effee', 0);

Problématique:

Je veux insérer dans la table semain_jour_horaire les informations suivantes:

id_semaine et id_jour et id_horaire pour un id_contact unique à condition
que pour chaque jour on à un horaire unique par exemple:
-----------------------------------------------
semaine 1 => jour 1 =lundi => horaire 1
semaine 1 => jour 2 =mardi => horaire 1
semaine 1 => jour 3 =mercredi => horaire 1
semaine 1 => jour 4 =mercredi => horaire 1
semaine 1 => jour 5 =vendredi => horaire 1
semaine 1 => jour 6 =samedi => horaire 5
semaine 1 => jour 7 =dimanche => horaire 5
-----------------------------------------------
semaine 2 => jour 1 =lundi => horaire 2
semaine 2 => jour 2 =mardi => horaire 2
semaine 2 => jour 3 =mercredi => horaire 2
semaine 2 => jour 4 =mercredi => horaire 3
semaine 2 => jour 5 =vendredi => horaire 4
semaine 2 => jour 6 =samedi => horaire 5
semaine 2 => jour 7 =dimanche => horaire 5

ma boucle d'insertion php:
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
$id_contact= mysql_insert_id ();
$id_semaine = array();
$id_jour = array();
$id_horaire = array();
$id_semaine = $_POST['semaines'];
$id_jour    = $_POST['jours'];
$id_horaire = $_POST['horaires'];
if(is_array($id_semaine) and is_array($id_jour) and is_array($id_horaire)){
	if(!empty($id_semaine) and !empty($id_jour) and !empty($id_horaire)){
		for($i=0;$i<count($id_semaine);$i++){
			if($id_semaine[$i]!="" && !empty($id_semaine[$i])){
				for($j=0;$j<count($id_jour);$j++){
					if($id_jour[$j]!="" && !empty($id_jour[$j])){
						for($k=0;$k<count($id_horaire);$k++){
							if($id_horaire[$k]!="" && !empty($id_horaire[$k])){
								$req_add2=mysql_query("insert into semaine_jour_horaire values('','".$id_semaine[$i]."','".$id_jour[$j]."','".$id_horaire[$k]."','".$id_contact."')");
							}
						}
					}
				}
			}
		}
	}
}
cette boucle fait l’insertion de 392 enregistrements
ce que je veux c'est l'insertion de 14 enregistrements pour un id_contact unique!

Merci de me donnée un code main!