Getting data from Backendless in PHP

Pharos

So I need to retreive the data from backendless and echo it properties one by one.

SO this is my Pasien.php class where there are setter and getter:

<?php
namespace Hospinet;

class Pasien
{
  private $Tgl_Lahir;
  private $Tgl_Masuk;
  private $Perawatan;
  private $No_Kamar;
  private $Nama_Pasien;
  private $No_Asuransi;
  private $Jenis_Asuransi;
  private $Jenis_Kamar;
  private $Id_RS;
  private $Id_Dokter;
  private $Id_Pasien;
  private $Gender;

  public function construct( $tgl_Lahir, $tgl_Masuk, $perawatan, $no_Kamar, $nama_Pasien, $no_Asuransi, $jenis_Asuransi, $jenis_Kamar, $id_RS, $id_Dokter, $id_Pasien, $gender ) {
      $this->Tgl_Lahir = $tgl_Lahir;
      $this->Tgl_Masuk = $tgl_Masuk;
      $this->Perawatan = $perawatan;
      $this->No_Kamar = $no_Kamar;
      $this->Nama_Pasien = $nama_Pasien;
      $this->No_Asuransi = $no_Asuransi;
      $this->Jenis_Asuransi = $jenis_Asuransi;
      $this->Jenis_Kamar = $jenis_Kamar;
      $this->Id_RS = $id_RS;
      $this->Id_Dokter = $id_Dokter;
      $this->Id_Pasien = $id_Pasien;
      $this->Gender = $gender;
  }

  public function getTgl_Lahir() {
    return $this->Tgl_Lahir;
  }

  public function setTgl_Lahir( $Tgl_Lahir ) {
      $this->Tgl_Lahir = $Tgl_Lahir;
  }


  public function getTgl_Masuk() {
    return $this->Tgl_Masuk;
  } 

  public function setTgl_Masuk( $Tgl_Masuk ) {
    $this->Tgl_Masuk = $Tgl_Masuk;
  }

  public function getPerawatan() {
    return $this->Perawatan;
  } 

  public function setPerawatan( $Perawatan ) {
    $this->Perawatan = $Perawatan;
  }

  public function getNo_Kamar() {
    return $this->No_Kamar;
  } 

  public function setNo_Kamar( $No_Kamar ) {
    $this->No_Kamar = $No_Kamar;
  }

  public function getNama_Pasien() {
    return $this->Nama_Pasien;
  } 

  public function setNama_Pasien( $Nama_Pasien ) {
    $this->Nama_Pasien = $Nama_Pasien;
  }

  public function getNo_Asuransi() {
    return $this->No_Asuransi;
  } 

  public function setNo_Asuransi( $No_Asuransi ) {
    $this->No_Asuransi = $No_Asuransi;
  }

  public function getJenis_Asuransi() {
    return $this->Jenis_Asuransi;
  } 

  public function setJenis_Asuransi( $Jenis_Asuransi ) {
    $this->Jenis_Asuransi = $Jenis_Asuransi;
  }

  public function getJenis_Kamar() {
    return $this->Jenis_Kamar;
  } 

  public function setJenis_Kamar( $Jenis_Kamar ) {
    $this->Jenis_Kamar = $Jenis_Kamar;
  }

  public function getId_RS() {
    return $this->Id_RS;
  } 

  public function setId_RS( $Id_RS ) {
    $this->Id_RS = $Id_RS;
  }

  public function getId_Dokter() {
    return $this->Id_Dokter;
  } 

  public function setId_Dokter( $Id_Dokter ) {
    $this->Id_Dokter = $Id_Dokter;
  }

  public function getId_Pasien() {
    return $this->Id_Pasien;
  } 

  public function setId_Pasien( $Id_Pasien ) {
    $this->Tgl_Masuk = $Tgl_Masuk;
  }

  public function getGender() {
    return $this->Gender;
  } 

  public function setGender( $Gender ) {
    $this->Gender = $Gender;
  }
}

I tried something like this in my index.php

<?php

namespace Hospinet;

use backendless\Backendless;

use backendless\services\persistence\BackendlessDataQuery;

use backendless\model\BackendlesCollection;

use Hospinet\Pasien;

include "backendless/autoload.php";

include "pasien.php";

Backendless::initApp('appid', 'REST key', 'v1');

$Pasien = new Pasien();

$result_collection = Backendless::$Persistence->of("Pasien")->find($data_query_or_relation_depth = null);

print_r( $result_collection->getAsArray() );

?>

And when I run it, this is what I got

backendless\model\BackendlessCollection Object
(

[data] => Array

(

[offset] => 0

[data] => Array

(

[0] => Array

(

[Id_Dokter] => C0E0607E

[created] => 1495593955000

[Gender] => L

[ownerId] => [Id_Pasien] => 1

[No_Asuransi] => H259030

[__meta] => {"relationRemovalIds":{},"selectedProperties":["Id_Dokter","created","Gender","ownerId","Id_Pasien","No_Asuransi","Nama_Pasien","No_Kamar","Tgl_Lahir","Perawatan","Jenis_Asuransi","Jenis_Kamar","Id_RS","___class","Tgl_Masuk","updated","objectId"],"relatedObjects":{}}

[Nama_Pasien] => Agustinus Kuncoro

[No_Kamar] => ICU-2

[Tgl_Lahir] => 29 Maret 1979

[Perawatan] => Hijau

[Jenis_Asuransi] => BPJS

[Jenis_Kamar] => ICU

[Id_RS] => 80923920

[___class] => Pasien

[Tgl_Masuk] => 17 Maret 2017

[updated] => 1495594474000

[objectId] => 347D197A-7235-04AB-FF0A-F9D5215F2F00

)

)

[nextPage] => [totalObjects] => 1

)

[stored_next_page_link] =>

)

Well it works, but what I want is to print the properties separately... something like this when I run the PHP code:

Name: Agustinus Kuncoro
Id = 1
Gender = L

I am new to PHP so I am really confused, could I use getter like in Android in PHP?

Scadge

The response is simply a native PHP Array, so you can work with it respectively:

print_r($result_collection->getAsArray()[0]['Id_Dokter'])
print_r($result_collection->getAsArray()[0]['Name_Pasien'])
print_r($result_collection->getAsArray()[0]['Gender'])

Or simpler with echo, since you need print_r only to print arrays:

echo $result_collection->getAsArray()[0]['Id_Dokter']
echo $result_collection->getAsArray()[0]['Name_Pasien']
echo $result_collection->getAsArray()[0]['Gender']

You can also iterate each item in array:

foreach ($result_collection->getAsArray() as &$item)
    echo $item['Id_Dokter'] . "\n";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting data from a webpage in PHP

From Dev

Getting data from a webpage in PHP

From Dev

Add data to table and get from table using Backendless.com

From Dev

Getting data from datatable then passing it to php with ajax

From Dev

Not getting Data from Database for user in PHP

From Dev

Php posting script not getting data from database

From Dev

PHP: Getting data from a JSON file

From Dev

Getting Data from PHP, JSON Highcharts?

From Dev

PHP Regex getting data from String and into array

From Dev

getting data from postgres to php to html (with ajax)

From Dev

Getting Data From Multiple Rows in PHP & MySQL

From Dev

Getting json data from a webpage using PHP

From Dev

Getting data from jquery loop in php

From Dev

getting JSON data from php page

From Dev

Getting data from database into a php array

From Dev

Php posting script not getting data from database

From Dev

PHP Session getting data from database

From Dev

Getting Data from PHP, JSON Highcharts?

From Dev

Getting data from url using PHP

From Dev

Getting data with PHP from Mysql database error

From Dev

Getting data from datatable then passing it to php with ajax

From Dev

Getting data from PHP with AJAX for the first time

From Dev

Getting data back from a PHP script

From Dev

Error in getting data from Json in PHP

From Dev

Php oop not getting data from db

From Dev

Populate swing JTable with Backendless data

From Dev

getting data from the form created with echo in php to another php

From Dev

Getting Data From stdClass Object From Facebook API with PHP

From Dev

Issue while getting data from URL. PHP