Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // echo 'Hello World start';
- header('Access-Control-Allow-Origin');
- $host = "localhost"; //Server name
- $user = "pnet1289_balna"; //mysql user name
- $pass = "Csakapalota321"; //mysql password
- $db = "pnet1289_balna_koncertek";
- // $host = "localhost"; //Server name
- // $user = "root"; //mysql user name
- // $pass = "admin"; //mysql password
- // $db = "balna";
- $connection = mysqli_connect("$host","$user","$pass")or die();
- mysqli_set_charset($connection, "utf8");
- mysqli_select_db($connection, $db);
- header('Content-Type: application/json');
- session_start();
- $query = "SELECT * FROM concerts";
- $select_concerts = mysqli_query($connection, $query);
- $resObj = [];
- while($row = mysqli_fetch_assoc($select_concerts)){
- $empObj = $row;
- $tempPrice = $empObj['price'];
- if(strcmp(strval($tempPrice), "NaN") < 0){
- $empObj['price'] = $tempPrice;
- if(!(intval($tempPrice, 0))){
- $empObj['price'] = "Ingyenes";
- } else {
- $empObj['price'] = $tempPrice." Ft";
- }
- } else {
- $empObj['price'] = $tempPrice;
- }
- array_push($resObj, $empObj);
- }
- $toReturn = array();
- for($i = 0; $i < count($resObj); $i++){
- $empReturn = (object)array(
- "date" => $resObj[$i]['date'],
- "place" => $resObj[$i]['place'],
- "price" => $resObj[$i]['price'],
- "event" => $resObj[$i]['event']);
- array_push($toReturn, $empReturn);
- }
- // echo $resObj[0]['event']."<br/>";
- // echo $resObj[1]['date']."<br/>";
- // echo $resObj[2]['price']."<br/>";
- // echo $resObj[3]['place']."<br/>";
- // $toReturn = (object)array("concerts" => $resObj);
- // echo (array)$toReturn['concerts'][0]['event'];
- $toReturn = (object)array("concerts" => $toReturn);
- echo json_encode($toReturn, JSON_UNESCAPED_UNICODE);
- // echo 'Hello World end';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement