2 function db_query_ng($result)
4 if ($result == FALSE) {
11 function runSQL($sql_string, $verify = false)
16 $db_name = 'ug7241_db';
18 $db_password = 'password';
20 $link = mysql_connect($host, $db_user, $db_password);
23 $res = mysql_db_query($db_name, $sql_string, $link);
25 // mysql_db_query returns either positive result ressource or true/false for an insert/update statement
29 errorpage('Database Problem', mysql_error($link)."\n<br />\n".$sql_string);
31 // ignore problem but forward the information
47 $sql = 'select release_ver from kps where name != "end"';
48 $result = runSQL($sql);
50 while ($row = mysql_fetch_array($result)) {
51 $row['release_ver'] = $row['release_ver']." ";
52 if (!in_array($row['release_ver'], $retarray)) {
53 $retarray[$i] = $row['release_ver'];
59 $retarray[$i] = trim($retarray[$i]);
61 return array_reverse($retarray);
64 /* Store name's info to $number
66 * $id: name of people or org
67 * $release: array of release info
68 * $key: what kind of info we store, example: set_num | line_num
70 * return: store the query result into it
72 function getinfo($name, $release, $key)
75 $count = count($release);
76 for ($i = 0; $i < $count; $i++
) {
79 $sql = 'select SUM('.$key.') from kps where name = "'.$name
80 .'" and release_ver = "'.$release[$i].'"';
81 $result = runSQL($sql);
83 if (!($row = mysql_fetch_array($result)))
85 $number[$i] = $row[0];
87 $sql = 'select * from kps where class = 1 and release_ver = "'.$release[$i].'"';
88 $result = runSQL($sql);
90 while ($row = mysql_fetch_array($result))
91 $number[$i] +
= $row[$key];
97 function getrank($name, $release, $key)
100 $count = count($release);
101 for ($i = 0; $i < $count; $i++
) {
104 $sql = 'select * from kps where name = "'.$name
105 .'" and release_ver = "'.$release[$i].'"';
106 $result = runSQL($sql);
107 db_query_ng($result);
108 if (!($row = mysql_fetch_array($result)))
110 $thiscount = $row[$key];
111 $thisclass = $row['class'];
113 $sql = 'select count(*) as amount from kps where class = '.
114 $thisclass.' and release_ver = "'.$release[$i].'"'.
115 ' and '.$key.' > '.$thiscount;
116 $result = runSQL($sql);
117 db_query_ng($result);
118 $row = mysql_fetch_row($result);
119 /* If there are x item before this,
120 * this should be ranked as x+1
122 $number[$i] = $row[0]+
1;
128 function getwho($class, $release)
131 $count = count($release);
132 for ($i = 0; $i < $count; $i++
) {
133 $sql = 'select count(id) from kps where class = '.$class
134 .' and release_ver = "'.$release[$i].'"';
135 $result = runSQL($sql);
136 db_query_ng($result);
137 $row = mysql_fetch_array($result);
144 function maxofarray($array)
147 $count = count($array);
148 for ($i = 0; $i < $count; $i++
)
149 if ($array[$i] > $ret)
154 function minofarray($array)
157 $count = count($array);
158 for ($i = 1; $i < $count; $i++
)
159 if ($array[$i] < $ret)
164 function id2name($id)
166 $sql = 'select * from kps where id = '.$id;
167 $result = runSQL($sql);
168 db_query_ng($result);
169 if (!($row = mysql_fetch_array($result)))
175 function name2id($name)
177 $sql = 'select * from kps where name = "'.$name.'"';
178 $result = runSQL($sql);
179 db_query_ng($result);
180 if (!($row = mysql_fetch_array($result)))