function getComment($id) { $dbQuery = sprintf("SELECT id,comment FROM comments WHERE id = '%s'", mysql_real_escape_string($id)); $result = getDBResultRecord($dbQuery); header("Content-type: application/json"); echo json_encode($result); }
function getTransaction($email) { $dbQuery = sprintf("SELECT name FROM Transaction WHERE email = '%s'", mysql_real_escape_string($email)); // $result = getDBResultRecord($dbQuery); //header("Content-type: application/json"); echo json_encode($result); }
function calcMinMaxMenteesPerMentor() { $query = "SELECT COUNT(*) FROM Mentee"; $result = getDBResultRecord($query); $numMentees = $result["COUNT(*)"]; $query = "SELECT COUNT(*) FROM Mentor"; $result = getDBResultRecord($query); $numMentors = $result["COUNT(*)"]; return ceil($numMentees / $numMentors); }
function assignAllMentees() { $query = "SELECT settingValue FROM GlobalSettings WHERE settingName='MaxMenteesPerMentor'"; $result = getDBResultRecord($query); $maxCount = $result["settingValue"]; //Get all unmatched mentees $menteeQuery = "SELECT Mentee.username FROM Mentee WHERE Mentee.username NOT IN (SELECT mentee_user FROM Matches)"; $mentees = getDBResultsArray($menteeQuery); //Get all mentors with open spots $mentorQuery = sprintf("SELECT Mentor.username AS username, COUNT(*) AS count\n\t\t\t\t\t\t FROM Mentor JOIN Matches ON Mentor.username = Matches.mentor_user\n\t\t\t\t\t\t GROUP BY Mentor.username HAVING COUNT(*) < %s ", $maxCount); $mentorQuery .= " UNION ALL SELECT Mentor.username AS username, 0 AS count\n\t\t\t\t\t\t FROM Mentor WHERE Mentor.username NOT IN (SELECT mentor_user FROM Matches)\n\t\t\t\t\t\t AND Mentor.approved = 1"; $mentors = getDBResultsArray($mentorQuery); $mentorIndex = 0; $currentCount = $mentors[0]['count']; foreach ($mentees as $mentee) { $insertQuery = sprintf("INSERT INTO Matches (mentor_user, mentee_user) VALUES ('%s', '%s')", $mentors[$mentorIndex]['username'], $mentee['username']); $result = getDBRegInserted($insertQuery); $currentCount++; if ($currentCount == $maxCount) { $mentorIndex++; $currentCount = $mentors[$mentorIndex]["count"]; } } }
function getFood($user) { $dbQuery = sprintf("SELECT freq , per from User_Info where ID = '%s'", mysql_real_escape_string($user)); $result = getDBResultRecord($dbQuery); echo json_encode($result); }