Bonjour ,

Je m'oriente vers vous pour un petit conseil.
En effet j'ai une table avec plusieurs avec différentes colonnes dont une avec la catégorie.

Je souhaiterais afficher le rendu à l'écran comme ci-dessous sous forme d'un tableau:

Catégorie 1
id1 info1
id3 info3


Catégorie 2
id2 info2
id4 info4

Pouvez-vous me donner un petit de coup de pouce pour me décrire brièvement la démarche à suivre je vous en serais reconnaissant.
Merci et bonne journée.

fetch.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
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
<?php
include('db.php');
include('function.php');
$query = '';
$output = array();
$query .= "SELECT *, DATE_FORMAT(date, '%d/%m/%Y') AS 'date', DATE_FORMAT(date2, '%d/%m/%Y') AS 'date2' FROM users ";
if(isset($_POST["search"]["value"]))
{
	$query .= 'WHERE categorie LIKE "%'.$_POST["search"]["value"].'%" ';
	$query .= 'OR first_name LIKE "%'.$_POST["search"]["value"].'%" ';
	$query .= 'OR last_name LIKE "%'.$_POST["search"]["value"].'%" ';
		$query .= 'OR date LIKE "%'.$_POST["search"]["value"].'%" ';
		$query .= 'OR date2 LIKE "%'.$_POST["search"]["value"].'%" ';
 
}
if(isset($_POST["order"]))
{
	$query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';
}
else
{
	$query .= 'ORDER BY date DESC, date2 DESC ';
}
if($_POST["length"] != -1)
{
	$query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
 
 
 
foreach($result as $row)
{
 
	//$date=$row["date2"];
 
					//$today = date("d-m-Y");
					//$today2 = date("d/m/Y", strtotime('+3 year'));
					//if ($today>$date){
						//$color="red";
					//}
 
						//else if ($today2>$date){
						//$color="orange";
					//}				 
 
 
						//else 
						//	{
							//	$color="black";
							//}
 
 
 $date  = DateTimeImmutable::createFromFormat('d/m/Y', $row['date2']);
$today = new DateTimeImmutable();
 
$color = 'red';
if ($date < $today) {
    if ($date >= $today->modify('-3 years')) {
        $color = 'red';
    } elseif ($date >= $today->modify('-5 years')) {
        $color = 'red';
		} 
 
 
    }
 
if ($date > $today) {
    if ($date <= $today->modify('+3 years')) {
        $color = 'orange';
    } elseif ($date <= $today->modify('+5 years')) {
        $color = 'black';
    }
 
 
 
}
 
 
	$image = '';
 
	if($row["image"] != '')
	{
		$image = '<a href="upload/'.$row["image"].'"" target="_blank"><IMG src="upload/pdf.png" alt=".pdf"></a>';
 
	}
	else
	{
		$image = '';
 
	}
	$image1 = '';
	if($row["image1"] != '')
	{
		$image1 = '<a href="certif/'.$row["image1"].'"" target="_blank"><IMG src="upload/pdf.png" alt=".pdf"></a>';
 
	}
	else
	{
		$image1 = '';
 
	}
 
	$sub_array = array();
 
 
	$sub_array[] = $image1;
	$sub_array[] = $image;
	$sub_array[] = $row["date"];
	$sub_array[] = '<font color="'.$color.'">'.$row["date2"].'</font>';
	$sub_array[] = $row["first_name"];
	$sub_array[] = $row["last_name"];
	$sub_array[] = '<a href="export.php?id='.$row['id'].'">voir</a>';
	$sub_array[] = $row["categorie"];
 
 
 
 
 
 
 
 
	$data[] = $sub_array;
}
$output = array(
	"draw"				=>	intval($_POST["draw"]),
	"recordsTotal"		=> 	$filtered_rows,
	"recordsFiltered"	=>	get_total_all_records(),
	"data"				=>	$data
);
echo json_encode($output);
 
 
 
 
 
 
 
 
 
?>
index.php
Code html : 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<html lang="fr">
	<head>
		<title>QUAPODES</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
		<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
		<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>		
		<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
 
		<style>
                        body
                        {
                                margin:0;
                                padding:0;
                                background-color:#f1f1f1;
                        }
                        .box
                        {
                                width:1270px;
                                padding:20px;
                                background-color:#fff;
                                border:1px solid #ccc;
                                border-radius:5px;
                                margin-top:25px;
                        }
                        
                        #hide { display: none; } 
                        
                        
                </style>
 
 
 
 
 
 
 
	</head>
	<body>
 
		<div class="container box">
			<h1 align="center">Suivi formations </h1>
			<br />
			<div class="table-responsive">
				<br />
				<div align="left">
				<a href="admin.php">  <img src="http://www.localhost/AjaxMultipleImageUpload/images/admin.png" alt="adminstration"/></a>
				</div>
				<div class='hide'><div align="right">
					<button type="button" id="add_button" data-toggle="modal" data-target="#userModal" class="btn btn-info btn-lg">Nouveau</button>
				</div></div>
				 <a href="contact-form/index.php" class="bouton">Contacter le webmestre</a><br />
 
 
				<br /><br />
	<div class="dropdown">
    <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
    <span class="caret"></span></button>
    <ul class="dropdown-menu">
      <input class="form-control" id="myInput" onkeyup="myFunction()" type="text" placeholder="Search..">
      <li id="exploitation" value="exploitation"><a href="#">exploitation</a></li>
      <li><a href="#">CSS</a></li>
      <li><a href="#">JavaScript</a></li>
      <li><a href="#">jQuery</a></li>
      <li><a href="#">Bootstrap</a></li>
      <li><a href="#">Angular</a></li>
    </ul>
  </div>
 
 
 
				<table id="user_data" class="table table-bordered table-striped data-order='[[ 3, 'desc' ]]' data-page-length='100'">
					<thead>
						<tr>
 
							<th width="3%">Visite M&eacute;dicale</th>
							<th width="3%">QUAPO</th>
							<th width="20%">Date de formation QUAPO</th>
							<th width="20%">Date de fin QUAPODES</th>
							<th width="20%">NOM</th>
							<th width="25%">Pr&eacute;nom</th>
							<th width="10%">Demander formation</th>
							<tr><th colspan="7">domaine</th></tr>
						</tr>
 
					</thead>
				</table>
 
			</div>
		</div>
	</body>
</html>
 
<div id="userModal" class="modal fade">
	<div class="modal-dialog">
		<form method="post" id="user_form" enctype="multipart/form-data">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Ajouter agent</h4>
				</div>
				<div class="modal-body">
					<label>Entrer date formation QUAPODES</label>
					<input type="date" name="date" id="date" class="form-control" />
					<br />
					<label>Entrer date de fin QUAPODES</label>
					<input type="date" name="date2" id="date2" class="form-control" />
					<br />
 
					<label>Entrer NOM</label>
					<input type="text" name="first_name" id="first_name" class="form-control" />
					<br />
					<label>Enter Prénom</label>
					<input type="text" name="last_name" id="last_name" class="form-control" />
					<br />
					<label>Selectionnez Formation Quapodes</label>
					<input type="file" name="user_image" id="user_image" />
					<span id="user_uploaded_image"></span><br>
 
					<label>Selectionnez visite médicale</label>
					<input type="file" name="user_image1" id="user_image1" />
					<span id="user_uploaded_image1"></span>
 
 
				</div>
				<div class="modal-footer">
					<input type="hidden" name="user_id" id="user_id" />
					<input type="hidden" name="operation" id="operation" />
					<input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				</div>
			</div>
		</form>
	</div>
</div>
 
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
        $('#add_button').click(function(){
                 
                $('#user_form')[0].reset();
                $('.modal-title').text("Add User");
                $('#action').val("Add");
                $('#operation').val("Add");
                $('#user_uploaded_image').html('');
                $('#user_uploaded_image1').html('');
        });
        
        var dataTable = $('#user_data').DataTable({
                "paging": false,
                "serverSide":true,
                "info":false,
                "order":[],
                "ajax":{
                        url:"fetch.php",
                        type:"POST"
                },
                "columnDefs":[
                        {
                                "targets":[0, 4],
                                "orderable":false,
                        },
                ],
        language: {
        processing:     "Traitement en cours...",
        search:         "Rechercher&nbsp;:",
        lengthMenu:    "Afficher _MENU_ &eacute;l&eacute;ments",
        info:           "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
        infoEmpty:      "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
        infoFiltered:   "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
        infoPostFix:    "",
        loadingRecords: "Chargement en cours...",
        zeroRecords:    "Aucun &eacute;l&eacute;ment &agrave; afficher",
        emptyTable:     "Aucune donnée disponible dans le tableau",
        paginate: {
            first:      "Premier",
            previous:   "Pr&eacute;c&eacute;dent",
            next:       "Suivant",
            last:       "Dernier"
        },
        aria: {
            sortAscending:  ": activer pour trier la colonne par ordre croissant",
            sortDescending: ": activer pour trier la colonne par ordre décroissant"
                        }
                }
        });
        
        
        $(document).on('submit', '#user_form', function(event){
                event.preventDefault();
                var date = $('#date').val();
                var date2 = $('#date2').val();
                
                var firstName = $('#first_name').val();
                var lastName = $('#last_name').val();
                var extension = $('#user_image').val().split('.').pop().toLowerCase();
                var extension = $('#user_image1').val().split('.').pop().toLowerCase();
                var categorie = $('#categorie').val();
                if(extension != '')
                {
                        if(jQuery.inArray(extension, ['gif','png','jpg','jpeg','pdf']) == -1)
                        {
                                alert("Invalid Image File");
                                $('#user_image').val('');
                                $('#user_image1').val('');
                                return false;
                        }
                        
                        
                        
                        
                        
                }       
                if(firstName != '' && lastName != '')
                {
                        $.ajax({
                                url:"insert.php",
                                method:'POST',
                                data:new FormData(this),
                                contentType:false,
                                processData:false,
                                success:function(data)
                                {
                                        alert(data);
                                        $('#user_form')[0].reset();
                                        $('#userModal').modal('hide');
                                        dataTable.ajax.reload();
                                }
                        });
                }
                else
                {
                        alert("Les champs sont requis");
                }
        });
        
        $(document).on('click', '.update', function(){
                var user_id = $(this).attr("id");
                $.ajax({
                        url:"fetch_single.php",
                        method:"POST",
                        data:{user_id:user_id},
                        dataType:"json",
                        success:function(data)
                        {
                                $('#userModal').modal('show');
                                        $('#date').val(data.date);
                                        $('#date2').val(data.date2);
                                $('#first_name').val(data.first_name);
                                $('#last_name').val(data.last_name);
                                $('.modal-title').text("Edit User");
                                $('#user_id').val(user_id);
                                $('#user_uploaded_image').html(data.user_image);
                                $('#user_uploaded_image1').html(data.user_image);
                                $('#action').val("Edit");
                                $('#operation').val("Edit");
                        }
                })
        });
        
        $(document).on('click', '.delete', function(){
                var user_id = $(this).attr("id");
                if(confirm("Etes-vous sur de vouloir l'effacer ?"))
                {
                        $.ajax({
                                url:"delete.php",
                                method:"POST",
                                data:{user_id:user_id},
                                success:function(data)
                                {
                                        alert(data);
                                        dataTable.ajax.reload();
                                }
                        });
                }
                else
                {
                        return false;   
                }
        });
        
        
});
 
 
 
 
</script>
 
 
 <script type="text/javascript" language="javascript" >
function myFunction() {
  var input, filter, table, tr, td, i, txtValue;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("user_data");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[7];
    if (td) {
      txtValue = td.textContent || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }       
  }
}
</script>