Advertisement
Guest User

Untitled

a guest
May 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2. // echo 'Hello World start';
  3. header('Access-Control-Allow-Origin');
  4. $host = "localhost"; //Server name
  5. $user = "pnet1289_balna"; //mysql user name
  6. $pass = "Csakapalota321"; //mysql password
  7. $db = "pnet1289_balna_koncertek";
  8. // $host = "localhost"; //Server name
  9. // $user = "root"; //mysql user name
  10. // $pass = "admin"; //mysql password
  11. // $db = "balna";
  12. $connection = mysqli_connect("$host","$user","$pass")or die();
  13. mysqli_set_charset($connection, "utf8");
  14. mysqli_select_db($connection, $db);
  15. header('Content-Type: application/json');
  16. session_start();
  17. $query = "SELECT * FROM concerts";
  18. $select_concerts = mysqli_query($connection, $query);
  19. $resObj = [];
  20. while($row = mysqli_fetch_assoc($select_concerts)){
  21. $empObj = $row;
  22. $tempPrice = $empObj['price'];
  23. if(strcmp(strval($tempPrice), "NaN") < 0){
  24. $empObj['price'] = $tempPrice;
  25. if(!(intval($tempPrice, 0))){
  26. $empObj['price'] = "Ingyenes";
  27. } else {
  28. $empObj['price'] = $tempPrice." Ft";
  29. }
  30. } else {
  31. $empObj['price'] = $tempPrice;
  32. }
  33. array_push($resObj, $empObj);
  34. }
  35. $toReturn = array();
  36. for($i = 0; $i < count($resObj); $i++){
  37. $empReturn = (object)array(
  38. "date" => $resObj[$i]['date'],
  39. "place" => $resObj[$i]['place'],
  40. "price" => $resObj[$i]['price'],
  41. "event" => $resObj[$i]['event']);
  42. array_push($toReturn, $empReturn);
  43. }
  44. // echo $resObj[0]['event']."<br/>";
  45. // echo $resObj[1]['date']."<br/>";
  46. // echo $resObj[2]['price']."<br/>";
  47. // echo $resObj[3]['place']."<br/>";
  48. // $toReturn = (object)array("concerts" => $resObj);
  49. // echo (array)$toReturn['concerts'][0]['event'];
  50. $toReturn = (object)array("concerts" => $toReturn);
  51. echo json_encode($toReturn, JSON_UNESCAPED_UNICODE);
  52. // echo 'Hello World end';
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement