From cf640f8670a10d785650e209900bd167aff2daf7 Mon Sep 17 00:00:00 2001 From: Mikhael Artur <mikhael.artur.d@gmail.com> Date: Fri, 6 Oct 2017 07:34:41 +0700 Subject: [PATCH] Added getter for pref loc in user model --- controller/edit-prefered-location.php | 20 ++++++++++++++++++++ controller/profile.php | 3 +-- model/user.php | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 controller/edit-prefered-location.php diff --git a/controller/edit-prefered-location.php b/controller/edit-prefered-location.php new file mode 100644 index 00000000..b4ae86a6 --- /dev/null +++ b/controller/edit-prefered-location.php @@ -0,0 +1,20 @@ +<?php + +/* Model */ +include "../model/user.php"; + +//TODO: tambahin redirect klo get kosong + +$user = new User; +$user_id = $_GET['id']; +$result = $user->getUserById($user_id); +header('Content-Type: text/xml'); +$xml = '<user>'; +while($row = mysqli_fetch_array($result)){ + $xml = $xml . '<name>' . $row['name'] . '</name><username>' . $row['username'] . + '</username><email>' . $row['email'] . '</email><image>' . $row['image'] . + '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; +} +$xml = $xml . '</user>'; + +print $xml; \ No newline at end of file diff --git a/controller/profile.php b/controller/profile.php index 922bc102..b4ae86a6 100644 --- a/controller/profile.php +++ b/controller/profile.php @@ -17,5 +17,4 @@ while($row = mysqli_fetch_array($result)){ } $xml = $xml . '</user>'; -print $xml; - +print $xml; \ No newline at end of file diff --git a/model/user.php b/model/user.php index 25a33243..8f69fea1 100644 --- a/model/user.php +++ b/model/user.php @@ -27,4 +27,23 @@ class User { mysqli_close($con); return $result; } + + function getPrefLocById($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con, 'projekers'); + $sql = "SELECT location FROM user WHERE id=" . $id; + $result = mysqli_query($con, $sql); + mysqli_close($con); + return $result; + } + + function getIdByUsernamePassword($username, $password){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con, 'projekers'); + $sql = "SELECT id FROM user WHERE username=" . $username . " and password=" . $password; + $result = mysqli_query($con, $sql); + mysqli_close($con); + return $result; + + } } \ No newline at end of file -- GitLab