Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.   session_start();
  3.   $servername = "localhost";
  4.   $username = "root";
  5.   $pass = "pass";
  6.   $dbName = "SheetPal";
  7.   $conn = mysqli_connect($servername , $username , $pass , $dbName);
  8.  
  9.   $userID = $_SESSION["userID"];
  10.   if(!$conn){
  11.     die("Connection failed: " . mysqli_connect_error());
  12.   }
  13.   else{
  14.     if(!$getWeek = $conn->prepare("SELECT date,task,paycode,starttime,finishtime,breaks,totalhours,comments FROM shifts WHERE userID = ? ORDER BY shiftID ASC")){
  15.       echo "Getweek prepare failed: (" . $conn->error . ")";
  16.     }
  17.     else{
  18.       if(!$getWeek->bind_param("s",$userID)){
  19.         echo "Getweek bind parameter: " . $getWeek->error;
  20.       }
  21.       else{
  22.         $getWeek->execute();
  23.         if( !$getWeek->bind_result($date, $task, $paycode, $starttime, $finishtime, $breaks, $totalhours, $comments) ){
  24.           echo "Getweek bind results failed: (" . $getWeek->errno . ") " . $getWeek->error;
  25.         }
  26.         else{
  27.           $shift = array();
  28.           while($getWeek->fetch()) {
  29.             $shiftObject = (object) [
  30.               "date" => $date,
  31.               "task" => $task,
  32.               "paycode" => $paycode,
  33.               "starttime" => $starttime,
  34.               "finishtime" => $finishtime,
  35.               "breaks" => $breaks,
  36.               "totalhours" => $totalhours,
  37.               "comments" => $comments,
  38.             ];
  39.             array_push($shift,$shiftObject);
  40.           }
  41.           echo json_encode($shift);
  42.         }
  43.       }
  44.     }
  45.   }
  46.   $conn->close();
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement