Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2. header("Content-Type:application/json");
  3. header("Access-Control-Allow-Origin: *");
  4.  
  5. $user = "kikit_app";
  6. $pass = "OP3N%8bSFx?,";
  7. $table = "kikit_app";
  8.  
  9. $db=new PDO("mysql:host=localhost;dbname=$table", $user, $pass);
  10.  
  11. $query = "SELECT * FROM steps";
  12.  
  13. try {
  14. $stmt = $db->query($query);
  15. }
  16. catch (PDOException $ex) {
  17. $response["success"] = 0;
  18. $response["message"] = "Database Error.";
  19. die(json_encode($response));
  20. }
  21.  
  22. $rows = $stmt->fetchAll();
  23.  
  24. if($rows) {
  25. $response["success"] = 1;
  26. $response["message"] = "Step";
  27. $response["step"] = array();
  28.  
  29. foreach ($rows as $row) {
  30. $post = array();
  31. $post["id"] = $row["intID"];
  32. $post["heading"] = $row["strStepheading"];
  33. $post["keyPrinciple"] = $row["strKeyPrinciple"];
  34. $post["pillar"] = $row["strPillar"];
  35. $post["introduction"] = $row["memIntroduction"];
  36. $post["actionSteps"] = $row["memActionSteps"];
  37. $post["actionPoints"] = $row["memActionPoints"];
  38. $post["studyAndUnderstanding"] = $row["memStudyUnderstanding"];
  39.  
  40. array_push($response["step"], $post);
  41. }
  42. echo json_encode($response);
  43. }
  44. else {
  45. $response["success"] = 0;
  46. $response["message"] = "No Steps Available";
  47. die(json_encode($response));
  48. }
  49. ?>
  50.  
  51. {"success":1,
  52. "message":
  53. "Step",
  54. "step":[{"id":"1",
  55. "heading":"Test Heading",
  56. "keyPrinciple":"Key Principle: Test Key Principle",
  57. "pillar":"Pillar 1: Pillar",
  58. "introduction":null,
  59. "actionSteps":null,
  60. "actionPoints":null,
  61. "studyAndUnderstanding":null}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement