-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBorrowerUtils.php
102 lines (85 loc) · 2.86 KB
/
BorrowerUtils.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
<?php
include"../includes/config/config.php";
class BorrowerUtils{
public static function check_ifexist($snumber, $firstname,$lastname){
$f_red = "color:red; font-family:Berlin Sans FB; font-size:20px; text-align:center; padding:4px;float: left;width: 1000px;background:#FFCCCC;border:groove solid red;margin-bottom:3px";
$sql = "SELECT * FROM borrowers WHERE student_id='{$snumber}' && firstname ='{$firstname}' && lastname='{$lastname}'";
$result = mysql_query($sql);
while ($borrowers= mysql_fetch_assoc($result)){
if ($result === True){
return False;
}else{
return True;
}
}
}
public static function addBorrower($snumber, $fname, $lname, $course, $address, $contact){
$query= "INSERT INTO borrowers(student_id, firstname, lastname, course, address, contact)
VALUES('{$snumber}','{$fname}','{$lname}','{$course}','{$address}','{$contact}')";
$result= mysql_query($query);
if($result){
return header("location:getBorrowers.php");
} else {
return FALSE;
}
}
public static function eachBorrower($id){
$query = "SELECT * FROM borrowers WHERE id={$id}";
$result=mysql_query($query) or die("Error in your query");
if(mysql_num_rows($result)>0){
$borrowers = array();
while($borrower=mysql_fetch_assoc($result)){
$borrowers[] = $borrower;
}
return $borrowers;
}else{
return NULL;
}
}
public static function getBorrowers(){
$query = "SELECT * FROM borrowers order by lastname asc";
$result=mysql_query($query) or die("Error in your query");
if(mysql_num_rows($result)>0){
$borrowers = array();
while($borrower=mysql_fetch_assoc($result)){
$borrowers[] = $borrower;
}
return $borrowers;
}else{
return NULL;
}
}
public static function getBorrowerCourse($course){
$query = "SELECT * FROM borrowers where course='{$course}' order by lname asc";
$result=mysql_query($query) or die("Error in your query");
if(mysql_num_rows($result)>0){
$res = array();
while($r=mysql_fetch_assoc($result)){
$res[] = $r;
}
return $res;
}else{
return NULL;
}
}
public static function deleteBorrower($id){
$query = "DELETE FROM borrowers WHERE id={$id}";
mysql_query($query) or die("Error in your query");
if(mysql_affected_rows()>0){
return true;
}else{
return $query;
}
}
public static function editBorrower($id, $snumber, $fname, $lname, $course, $address, $contact){
$query = "UPDATE borrowers SET student_id='{$snumber}', firstname='{$fname}', lastname='{$lname}',
course='{$course}', address='{$address}', contact='{$contact}' WHERE id={$id}";
mysql_query($query) or die("Error in your query");
if(mysql_affected_rows()>0){
return header("location:eachBorrower.php?id={$id}");
}else{
return false;
}
}
}
?>