Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 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.   $currentStart = $_POST["currentStart"];
  11.   $currentEnd = $_POST["currentEnd"];
  12.  
  13.   if(!$conn){
  14.     die("Connection failed: " . mysqli_connect_error());
  15.   }
  16.   $getWeek = $getWeek = $conn->prepare("SELECT date,task,paycode,starttime,finishtime,breaks,totalhours,comments
  17.                                        FROM shifts
  18.                                        WHERE userID = ?
  19.                                        AND date > ?
  20.                                        AND date < ?
  21.                                        ORDER BY shiftID ASC");
  22.   $getWeek->bind_param("s",$userID);
  23.   $getWeek->execute();  
  24.   $getWeek->bind_result($date, $task, $paycode, $starttime, $finishtime, $breaks, $totalhours, $comments);
  25.   $shift = array();
  26.   while($getWeek->fetch()){
  27.     $shiftObject = (object) [
  28.       "date" => $date,
  29.       "task" => $task,
  30.       "paycode" => $paycode,
  31.       "starttime" => $starttime,
  32.       "finishtime" => $finishtime,
  33.       "breaks" => $breaks,
  34.       "totalhours" => $totalhours,
  35.       "comments" => $comments
  36.     ];
  37.     array_push($shift,$shiftObject);
  38.   }
  39.   echo json_encode($shift);
  40.   $conn->close();
  41. //   echo json_encode($shift);
  42. //   else{
  43. //     if(!$getWeek = $conn->prepare("SELECT date,task,paycode,starttime,finishtime,breaks,totalhours,comments FROM shifts WHERE userID = ? ORDER BY shiftID ASC")){
  44. //       echo "Getweek prepare failed: (" . $conn->error . ")";
  45. //     }
  46. //     else{
  47. //       if(!$getWeek->bind_param("s",$userID)){
  48. //         echo "Getweek bind parameter: " . $getWeek->error;
  49. //       }
  50. //       else{
  51. //         $getWeek->execute();
  52. //         if( !$getWeek->bind_result($date, $task, $paycode, $starttime, $finishtime, $breaks, $totalhours, $comments) ){
  53. //           echo "Getweek bind results failed: (" . $getWeek->errno . ") " . $getWeek->error;
  54. //         }
  55. //         else{
  56. //           $shift = array();
  57. //           while($getWeek->fetch()) {
  58. //             $shiftObject = (object) [
  59. //               "date" => $date,
  60. //               "task" => $task,
  61. //               "paycode" => $paycode,
  62. //               "starttime" => $starttime,
  63. //               "finishtime" => $finishtime,
  64. //               "breaks" => $breaks,
  65. //               "totalhours" => $totalhours,
  66. //               "comments" => $comments,
  67. //             ];
  68. //             array_push($shift,$shiftObject);
  69. //           }
  70. //           echo json_encode($shift);
  71. //         }
  72. //       }
  73. //     }
  74. //   }
  75. //   $conn->close();
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement