Nav apraksta

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?PHP
  2. // ---------------
  3. // Connection to server and database
  4. // ---------------
  5. $host = "localhost";
  6. $basedatos = "techos";
  7. $user = "pablo.puig1";
  8. $passw = "9NA3kSExI2fGE6eV";
  9. try{
  10. $connection = mysqli_connect($host, $user, $passw, $basedatos) or $error = 1;
  11. }
  12. catch(Exception $ex){
  13. print("Error connecting to database: ". $ex->getMessage()) and die();
  14. }
  15. // //---------------
  16. // // Query and sending results
  17. // //---------------
  18. header('Content-Type: application/json');
  19. $encodedData=file_get_contents('php://input');
  20. $decodedData=json_decode($encodedData, true);
  21. $FindEID=$decodedData["FindEID"];
  22. $query= "SELECT eid, name, start_date, end_date, participant_count, participant_limit, description from events";
  23. $stmt=mysqli_prepare($connection, $query);
  24. mysqli_stmt_execute($stmt);
  25. mysqli_stmt_bind_result($stmt, $eid, $name, $start_date, $end_date, $participant_count, $participant_limit, $description);
  26. while(mysqli_stmt_fetch($stmt)){
  27. $response[] = array("id"=>$eid, "activityName"=>$name, "subscribed"=> false, "icon"=> 'person-add-outline', "startDate"=>$start_date, "endDate"=>$end_date, "totalSubscribed"=>$participant_count, "maxSubscribed"=>$participant_limit, "activityDescription"=>$description);
  28. }
  29. // if(mysqli_num_rows($stmt)>0)
  30. // {
  31. // $Row = mysqli_fetch_assoc($stmt);
  32. // $eid = $Row['eid'];
  33. // $name = $Row['name'];
  34. // $start_date = $Row['start_date'];
  35. // $end_date = $Row['end_date'];
  36. // $participant_count = $Row['participant_count'];
  37. // $participant_limit = $Row['participant_limit'];
  38. // $description = $Row['description'];
  39. // }
  40. // else
  41. // {
  42. // $eid = "";
  43. // $name = "";
  44. // $start_date = "";
  45. // $end_date = "";
  46. // $participant_count = "";
  47. // $participant_limit = "";
  48. // $description = "";
  49. // }
  50. // ----------------------------------------------
  51. // $eid = '1';
  52. // $name = 'testEvent';
  53. // $start_date = '2023-01-07';
  54. // $end_date = '2023-01-23';
  55. // $participant_count = '13';
  56. // $participant_limit = '20';
  57. // $description = 'TEST TEST TEST TEST TEST TEST TEST TEST';
  58. //-----------------------------------------------
  59. // $response[] = array("eid"=>$eid, "name"=>$name, "Sdate"=>$start_date, "Edate"=>$end_date, "Pcount"=>$participant_count, "Plimit"=>$participant_limit, "description"=>$description);
  60. echo json_encode($response);
  61. // $TPMGJson = json_encode($response);
  62. // file_put_contents('./events.json', $TPMGJson);
  63. // echo $TPMGJson;
  64. ?>