-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdateGroups.php
More file actions
executable file
·22 lines (17 loc) · 913 Bytes
/
updateGroups.php
File metadata and controls
executable file
·22 lines (17 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$authorID = $_REQUEST['authorID'];
$students=json_decode($_POST['students']);
$db = new PDO('mysql:host=localhost;dbname=group_maker', 'root', 'password',array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); //From: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
$stmt = $db->prepare("SELECT * FROM classes where authorId=?"); //prepare insert
$stmt->execute(array($authorID));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$areGroupsMade = $rows[0]['groupsMade'];
$classID = $rows[0]['classId'];
for($i = 0; $i < sizeOf($students); $i++){
for($j = 0; $j < sizeOf($students[$i]); $j++){
$stmt = $db->prepare("UPDATE students SET groupNumber = ($i + 1) where class=? AND name=?");
$stmt->execute(array($classID, $students[$i][$j]));
// echo($students[$i][$j]);
}
}
?>