-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_student.php
185 lines (125 loc) · 5.7 KB
/
add_student.php
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
<?php include('header_dashboard.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
<body>
<?php include('navbar_teacher.php'); ?>
<div class="container-fluid">
<div class="row-fluid">
<?php include('class_sidebar.php'); ?>
<div class="span9" id="content">
<div class="row-fluid">
<!-- breadcrumb -->
<div class="pull-right">
<a href="my_students.php<?php echo '?id='.$get_id; ?>" class="btn btn-info"><i class="icon-arrow-left"></i> Back</a>
</div>
<?php $class_query = mysqli_query($conn,"select * from teacher_class
LEFT JOIN class ON class.class_id = teacher_class.class_id
LEFT JOIN subject ON subject.subject_id = teacher_class.subject_id
where teacher_class_id = '$get_id'")or die(mysqli_error());
$class_row = mysqli_fetch_array($class_query);
?>
<ul class="breadcrumb">
<li><a href="#"><?php echo $class_row['class_name']; ?></a> <span class="divider">/</span></li>
<li><a href="#"><?php echo $class_row['subject_code']; ?></a> <span class="divider">/</span></li>
<li><a href="#">My Students</a><span class="divider">/</span></li>
<li><a href="#"><b>Add Student</b></a></li>
</ul>
<!-- end breadcrumb -->
<!-- block -->
<div id="block_bg" class="block">
<div class="navbar navbar-inner block-header">
<div id="" class="muted pull-left"></div>
</div>
<div class="block-content collapse in">
<div class="span12">
<form method="post" action="">
<button name="submit" type="submit" class="btn btn-info"><i class="icon-save"></i> Add Student</button>
<br>
<br>
<table cellpadding="0" cellspacing="0" border="0" class="table" id="example">
<thead>
<tr>
<th>Photo</th>
<th>Name</th>
<th>Course Year and Section</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$a = 0 ;
$query = mysqli_query($conn,"select * from student LEFT JOIN class on class.class_id = student.class_id
") or die(mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$id = $row['student_id'];
$a++;
?>
<tr>
<input type="hidden" name="test" value="<?php echo $a; ?>">
<td width="70"><img class="img-rounded" src="admin/<?php echo $row['location']; ?>" height="50" width="40"></td>
<td><?php echo $row['firstname'] . " " . $row['lastname']; ?></td>
<td><?php echo $row['class_name']; ?></td>
<td width="80">
<select name="add_student<?php echo $a; ?>" class="span12">
<option></option>
<option>Add</option>
</select>
<input type="hidden" name="student_id<?php echo $a; ?>" value="<?php echo $id; ?>">
<input type="hidden" name="class_id<?php echo $a; ?>" value="<?php echo $get_id; ?>">
<input type="hidden" name="teacher_id<?php echo $a; ?>" value="<?php echo $session_id; ?>">
</td>
<?php } ?>
</tr>
</tbody>
</table>
</form>
<?php
if (isset($_POST['submit'])){
$test = $_POST['test'];
for($b = 1; $b <= $test; $b++)
{
$test1 = "student_id".$b;
$test2 = "class_id".$b;
$test3 = "teacher_id".$b;
$test4 = "add_student".$b;
$id = $_POST[$test1];
$class_id = $_POST[$test2];
$teacher_id = $_POST[$test3];
$Add = $_POST[$test4];
$query = mysqli_query($conn,"select * from teacher_class_student where student_id = '$id' and teacher_class_id = '$class_id' ")or die(mysqli_error());
$count = mysqli_num_rows($query);
if ($count > 0){ ?>
<script>
alert('Student Already in the class');
</script>
<script>
window.location = "add_student.php<?php echo '?id='.$get_id; ?>";
</script>
<?php
}else
if($Add == 'Add'){
mysqli_query($conn,"insert into teacher_class_student (student_id,teacher_class_id,teacher_id) values('$id','$class_id','$teacher_id') ")or die(mysqli_error());
}else{
}
?>
<script>
window.location = "my_students.php<?php echo '?id='.$get_id; ?>";
</script>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- /block -->
</div>
</div>
</div>
<?php include('footer.php'); ?>
</div>
<?php include('script.php'); ?>
</body>
</html>