· 10 years ago · Jun 17, 2016, 04:30 AM
1<script src="jquery.js"></script>
2<!--<script src="jquery.min.js"></script> -->
3<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>-->
4<html>
5<head><title>Checkbox Demo</title></head>
6<form class="form-horizontal" action="selectall.php" method="post">
7
8<input type='button' name='Check_All' value='Check All' onClick='$(":checkbox").attr("checked",true);'>
9<input type='button' name='Un_CheckAll' value='Un Check All' onClick='$(":checkbox").attr("checked",false);'>
10
11<table align="center" style="width:100%">
12<tr>
13
14<th width="450"><strong>Form Name</strong></th>
15<th width="150"><strong>select</strong></th>
16<th width="150"><strong>Edit</strong> </th>
17<th width="150"><strong>Delete</strong></th>
18<th width="150"><strong>View</strong></th>
19</tr>
20<tr>
21<td style="padding-left:20%"><input name="a1" type="hidden" value="Authentication">Authentication</td>
22<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" class="case"/> </td>
23
24</tr>
25<tr>
26<td style="padding-left:20%"><input name="a2" type="hidden" value="User">User</td>
27<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
28
29</tr>
30<tr>
31<td style="padding-left:20%"><input name="a3" type="hidden" value="Change User_Password">Change User_Password</td>
32<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
33
34<tr>
35<tr>
36<td style="padding-left:20%"><input name="a4" type="hidden" value="Add Employee Details">Add Employee Details</td>
37<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
38
39</tr>
40<tr>
41<td style="padding-left:20%"><input name="a5" type="hidden" value="All Employee">All Employee </td>
42<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
43<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
44<td style="padding-left:8%"> <input type="checkbox" id="" name="emailid[]" value="1"/></td>
45<td style="padding-left:8%"> <input type="checkbox" id="" name="emailid[]" value="1"/></td>
46</tr>
47<tr>
48<td style="padding-left:20%"><input name="a6" type="hidden" value="Company Profile">Company Profile </td>
49<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
50<td style="padding-left:8%"><input type="checkbox" id="" name="emailid[]" value="1" /></td>
51<td style="padding-left:8%"> <input type="checkbox" id="" name="emailid[]" value="1"/></td>
52<td style="padding-left:8%"> <input type="checkbox" id="" name="emailid[]" value="1"/></td>
53</tr>
54</table>
55</div>
56</div>
57</div>
58</div>
59</div>
60
61<input type="submit" name="submit" value="SAVE" class="btn btn-info">
62</form>
63
64</html>
65
66<?php
67include('DB.class.php');
68//create an instance of the DB class
69$db = new DB();
70$db->connect();
71if(isset($_POST['emailid'])){
72
73
74foreach($_POST['emailid'] as $selected){
75echo $selected;
76
77$data["as1"]=$selected;
78
79$data["as2"]=$selected;
80
81$data["as3"]=$selected;
82
83$data["as4"]=$selected;
84
85$data["as5"]=$selected;
86$data["ae5"]=$selected;
87$data["ad5"]=$selected;
88$data["av5"]=$selected;
89
90$data["as6"]=$selected;
91$data["ae6"]=$selected;
92$data["ad6"]=$selected;
93$data["av6"]=$selected;
94}
95}
96$db->Insert("selectdemot",$data);
97?>
98
99<?php
100//DB.class.php
101/*****************************************************************************
102/*Copyright (C) 2013 Narwade Jaywant
103For any details please feel free to contact me at info@technopia.in
104/*****************************************************************************/
105class DB {
106
107protected $db_name = 'selectdemo';
108protected $db_user = 'root';
109protected $db_pass = '';
110protected $db_host = 'localhost';
111/*protected $db_name = 'infortte_yogesh';
112protected $db_user = 'infortte_yogesh';
113protected $db_pass = 'Yogesh@123';
114protected $db_host = 'localhost';*/
115
116//Constructor is called whenever a new object is created.
117function __construct() {
118$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
119mysql_select_db($this->db_name);
120
121return true;
122}
123public function connect(){
124$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
125mysql_select_db($this->db_name);
126
127return true;
128}
129//takes a mysql row set and returns an associative array, where the keys
130//in the array are the column names in the row set. If singleRow is set to
131//true, then it will return a single row instead of an array of rows.
132public function processRowSet($rowSet, $singleRow=false)
133{
134$resultArray = array();
135while($row = mysql_fetch_assoc($rowSet))
136{
137array_push($resultArray, $row);
138}
139
140if($singleRow === true)
141return $resultArray[0];
142
143return $resultArray;
144}
145
146//Select rows from the database.
147//returns a full row or rows from $table using $where as the where clause.
148//return value is an associative array with column names as keys.
149public function SelectTable($table, $where="",$fieldarray="",$debug="") {
150if ($fieldarray=="")
151{
152$f_list = "*";
153}
154else
155{
156$f_list = $fieldarray ;
157}
158$sql = "SELECT $f_list FROM $table ";
159if( ! empty( $where ) )
160$sql .= " WHERE $where";
161
162if($debug==1){echo $sql;exit();}
163$result = mysql_query($sql);
164if( ! $result )
165return 0;
166return $this->processRowSet($result);
167}
168public function SelectSingle($table, $where,$fieldarray="",$debug="") {
169if ($fieldarray=="")
170{
171$f_list = "*";
172}
173else
174{
175$f_list = $fieldarray ;
176}
177$sql = "SELECT $f_list FROM $table ";
178if( ! empty( $where ) )
179$sql .= " WHERE $where";
180
181if($debug==1){echo $sql;exit();}
182$result = mysql_query($sql);
183if( ! $result )
184return 0;
185if(mysql_num_rows($result) == 1)
186return $this->processRowSet($result, true);
187}
188//Updates a current row in the database.
189//takes an array of data, where the keys in the array are the column names
190//and the values are the data that will be inserted into those columns.
191//$table is the name of the table and $where is the sql where clause.
192public function Update($table,$where,$data,$debug="") {
193
194foreach ( $data as $column=>$value )
195{
196if($value !="now()"){
197$fv[] = "$column = ""."$value".""";
198}else{
199$fv[]= "$column = "."$value"."";
200}
201}
202$fv_list = trim(implode(", ", $fv));
203
204$sql = "UPDATE $table SET "."$fv_list"." WHERE $where";
205if($debug==1){echo $sql;exit();}
206mysql_query($sql) or die(mysql_error());
207return true;
208}
209
210//Inserts a new row into the database.
211//takes an array of data, where the keys in the array are the column names
212//and the values are the data that will be inserted into those columns.
213//$table is the name of the table.
214public function Insert($table,$data,$debug="") {
215
216$columns = "";
217$values = "";
218foreach( $data as $column=>$value )
219{
220$field[] = $column;
221if($value !="now()")
222$values[] = "'$value'";
223else
224$values[] = "$value";
225}
226$columns = trim( implode(", ", $field) );
227$values = trim( implode(", ", $values) );
228
229$sql = "insert into $table ($columns) values ($values)";
230if($debug==1){echo $sql;exit();}
231mysql_query($sql) or die(mysql_error());
232
233//return the ID of the user in the database.
234return mysql_insert_id();
235
236}
237public function Delete($table, $condition)
238{
239
240$query = "DELETE FROM $table WHERE $condition";
241$result = mysql_query( $query);
242if( ! $result )
243return 0;
244return 1;
245}
246
247}
248?>
249
250CREATE TABLE IF NOT EXISTS `selectdemot` (
251`sr_no` int(11) NOT NULL,
252 `as1` enum('0','1','','') NOT NULL,
253 `as2` enum('0','1','','') NOT NULL,
254 `as3` enum('0','1','','') NOT NULL,
255 `as4` enum('0','1','','') NOT NULL,
256 `as5` enum('0','1','','') NOT NULL,
257 `ae5` enum('0','1','','') NOT NULL,
258 `ad5` enum('0','1','','') NOT NULL,
259 `av5` enum('0','1','','') NOT NULL,
260 `as6` enum('0','1','','') NOT NULL,
261 `ae6` enum('0','1','','') NOT NULL,
262 `ad6` enum('0','1','','') NOT NULL,
263 `av6` enum('0','1','','') NOT NULL
264) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
265
266INSERT INTO `selectdemot` (`sr_no`, `as1`, `as2`, `as3`, `as4`, `as5`, `ae5`, `ad5`, `av5`, `as6`, `ae6`, `ad6`, `av6`) VALUES
267(1, '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'),
268(2, '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1');
269
270<form class="form-horizontal" action="selectall.php" method="post">
271 <!--selectall.php-->
272
273 <input type='button' name='Check_All' value='Check All' onClick='$(":checkbox").attr("checked",true);'>
274 <input type='button' name='Un_CheckAll' value='Un Check All' onClick='$(":checkbox").attr("checked",false);'>
275 <table align="center" style="width:100%">
276 <tr>
277 <th width="450"><strong>Form Name</strong></th>
278 <th width="150"><strong>select</strong></th>
279 <th width="150"><strong>Edit</strong> </th>
280 <th width="150"><strong>Delete</strong></th>
281 <th width="150"><strong>View</strong></th>
282 </tr>
283 <tr>
284 <td style="padding-left:20%"><input name="a1" type="hidden" value="Authentication">
285 Authentication</td>
286 <td style="padding-left:8%">
287 <input type="hidden" name="auth[1]" value="0" />
288 <input type="checkbox" id="" name="auth[1]" value="1" class="case"/>
289 </td>
290 </tr>
291 <tr>
292 <td style="padding-left:20%"><input name="a2" type="hidden" value="User">
293 User</td>
294 <td style="padding-left:8%">
295 <input type="hidden" name="user[1]" value="0" />
296 <input type="checkbox" id="" name="user[1]" value="1" />
297 </td>
298 </tr>
299 <tr>
300 <td style="padding-left:20%"><input name="a3" type="hidden" value="Change User_Password">
301 Change User_Password</td>
302 <td style="padding-left:8%">
303 <input type="hidden" name="passmod[1]" value="0" />
304 <input type="checkbox" id="" name="passmod[1]" value="1" />
305 </td>
306 <tr>
307 <tr>
308 <td style="padding-left:20%"><input name="a4" type="hidden" value="Add Employee Details">
309 Add Employee Details</td>
310 <td style="padding-left:8%">
311 <input type="hidden" name="employee[1]" value="0" />
312 <input type="checkbox" id="" name="employee[1]" value="1" />
313 </td>
314 </tr>
315 <tr>
316 <td style="padding-left:20%"><input name="a5" type="hidden" value="All Employee">
317 All Employee </td>
318 <td style="padding-left:8%">
319 <input type="hidden" name="emp_select[1]" value="0" />
320 <input type="checkbox" id="" name="emp_select[1]" value="1" />
321 </td>
322 <td style="padding-left:8%">
323 <input type="hidden" name="emp_edit[1]" value="0" />
324 <input type="checkbox" id="" name="emp_edit[1]" value="1" />
325 </td>
326 <td style="padding-left:8%">
327 <input type="hidden" name="emp_delete[1]" value="0" />
328 <input type="checkbox" id="" name="emp_delete[1]" value="1"/>
329 </td>
330 <td style="padding-left:8%">
331 <input type="hidden" name="emp_view[1]" value="0" />
332 <input type="checkbox" id="" name="emp_view[1]" value="1"/>
333 </td>
334 </tr>
335 <tr>
336 <td style="padding-left:20%"><input name="a6" type="hidden" value="Company Profile">
337 Company Profile </td>
338 <td style="padding-left:8%">
339 <input type="hidden" name="profile_select[1]" value="0" />
340 <input type="checkbox" id="" name="profile_select[1]" value="1" />
341 </td>
342 <td style="padding-left:8%">
343 <input type="hidden" name="profile_edit[1]" value="0" />
344 <input type="checkbox" id="" name="profile_edit[1]" value="1" />
345 </td>
346 <td style="padding-left:8%">
347 <input type="hidden" name="profile_delete[1]" value="0" />
348 <input type="checkbox" id="" name="profile_delete[1]" value="1"/>
349 </td>
350 <td style="padding-left:8%">
351 <input type="hidden" name="profile_view[1]" value="0" />
352 <input type="checkbox" id="" name="profile_view[1]" value="1"/>
353 </td>
354 </tr>
355 </table>
356 <input type="submit" name="submit" value="SAVE" class="btn btn-info">
357</form>
358
359Array
360(
361 [a1] => Authentication
362 [auth] => Array
363 (
364 [1] => 1
365 )
366
367 [a2] => User
368 [user] => Array
369 (
370 [1] => 0
371 )
372
373 [a3] => Change User_Password
374 [passmod] => Array
375 (
376 [1] => 0
377 )
378
379 [a4] => Add Employee Details
380 [employee] => Array
381 (
382 [1] => 1
383 )
384
385 [a5] => All Employee
386 [emp_select] => Array
387 (
388 [1] => 0
389 )
390
391 [emp_edit] => Array
392 (
393 [1] => 0
394 )
395
396 [emp_delete] => Array
397 (
398 [1] => 1
399 )
400
401 [emp_view] => Array
402 (
403 [1] => 0
404 )
405
406 [a6] => Company Profile
407 [profile_select] => Array
408 (
409 [1] => 1
410 )
411
412 [profile_edit] => Array
413 (
414 [1] => 1
415 )
416
417 [profile_delete] => Array
418 (
419 [1] => 0
420 )
421
422 [profile_view] => Array
423 (
424 [1] => 1
425 )
426
427 [submit] => SAVE
428)