# Send multiple data to database using rest API in Ionic3

**URL:** <https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577>\
**Category:** ionic-v3\
**Created:** [October 15, 2018, 11:52am UTC](https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577 "2018-10-15T11:52:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![M014](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@M014](https://forum.ionicframework.com/u/M014)\
**Post date:** [October 15, 2018, 11:52am UTC](https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577/1 "2018-10-15T11:52:36Z")

</div>

I had a list of students, with toggle button I need it to be checked by default and store its value in a variable with respect to student id and send it to the database (if toggle true send value 1 to the respected student ID else 0 to the respect ID).

stud.html

```auto
<ion-list>
        <!-- Select Medium -->
        <ion-item>
            <ion-label>Medium:</ion-label>
            <ion-select [(ngModel)]="mediumId" (ionChange)="selectedMedium(id)" class="optionsStyle" placeholder="Select">
                <ion-option *ngFor="let list of getListMedium" value="{{list.Medium_Id}}">{{list.Medium_Name}}</ion-option>
            </ion-select>
        </ion-item>

        <!-- Select Standard -->
        <ion-item>
            <ion-label>Standard:</ion-label>
            <ion-select [(ngModel)]="standardId" (ionChange)="selectedStandard(id)" class="optionsStyle" placeholder="Select">
                <ion-option *ngFor="let list of getListStandard" value="{{list.Standard_Id}}">{{list.Standard_Name}}</ion-option>
            </ion-select>
        </ion-item>

        <ion-item>
            <ion-label>Section:</ion-label>
            <ion-select [(ngModel)]="sectionId" (ionChange)="selectedSection(id)" class="optionsStyle" placeholder="Select">
                <ion-option *ngFor="let list of getListSection" value="{{list.Section_Id}}">{{list.Section_Name}}</ion-option>
            </ion-select>
        </ion-item>

        
            <ion-item *ngFor="let list of getStudentList">
                <ion-label>{{list.Student_FirstName}}</ion-label>
                <ion-toggle [(ngModel)]="list.Student_LastName" (ionChange)="changeToggle(list)"></ion-toggle>
            </ion-item>

            <button ion-button full *ngIf="getStudentList" (click)="sendAttendanceStstus(getStudentList)">Submit</button>
        
    </ion-list>

```

stud.ts

```auto
ionViewDidEnter() {
        this.restAttendance.getStudentAttendanceStreamDetails()
            .then(data => {
                this.getListStream = data;
                console.log(this.getListStream);
            });
    }
    //MediumId
    selectedMedium(id) {
        console.log(this.streamId + this.mediumId);

        id = this.mediumId;

        this.restAttendance.getStudentAttendanceStandardDetails(this.streamId, this.mediumId)
            .then(data => {
                this.getListStandard = data;
                console.log(this.getListStandard);
            });
    }

    //StandardId
    selectedStandard(id) {
        console.log(this.standardId);

        id = this.standardId;

        this.restAttendance.getStudentAttendanceSectionDetails(this.streamId, this.mediumId, this.standardId)
            .then(data => {
                this.getListSection = data;
                console.log(this.getListSection);
            });
    }

    //SectionId
    selectedSection(id) {
        console.log(this.sectionId);

        id = this.sectionId;

        this.restAttendance.getStudentAttendanceList(this.streamId, this.mediumId, this.standardId, this.sectionId)
            .then(data => {
                this.getStudentList = data;
                console.log(this.getStudentList);
            });
    }

    changeToggle(list) {
        console.log(list.Student_Id + list.Student_LastName);
    }

    sendAttendanceStstus(getStudentList) {

        if (!this.streamId || !this.mediumId || !this.standardId || !this.sectionId) {
            let alert = this.alertCtrl.create({
                title: "Select",
                subTitle: "please select all details",
                buttons: ['ok']
            }).present();
            console.log("Select details");
        } else {
            console.log('StreamId: '+ this.streamId + ' mediumId: ' + this.mediumId + ' StandardId: ' + this.standardId + ' SectionId: ' + this.sectionId + ' '+getStudentList);
            // this.restAttendance.postStudentAttendanceDetails(this.streamId, this.mediumId, this.standardId, this.sectionId, this.studentId, this.Student_Name)
            // .then(data => {
            // console.log(data);
            // this.nvCtrl.push(DashboardPage);
            // }).catch(err => {
            // console.log(err);
            // });
        }

    }

```

rest provider

```auto
getStudentAttendanceMediumDetails(id) {
    return new Promise(resolve => {
      this.http.get(this.apiMedium+'?Id='+id).subscribe(data => {
        resolve(data);
        console.log(data);
        console.log(this.apiMedium+'?Id='+id);
      }, err => {
        console.log(err);
      });
    });
  }

  getStudentAttendanceStandardDetails(streamId, mediumId) {
    return new Promise(resolve => {
      this.http.get(this.apiStandard+'?StreamId='+streamId+'&MediumId='+mediumId).subscribe(data => {
        resolve(data);
        console.log(data);
        console.log(this.apiStandard+'?StreamId='+streamId+'&MediumId='+mediumId);
      }, err => {
        console.log(err);
      });
    });
  }

  getStudentAttendanceSectionDetails(streamId, mediumId, standardId){
    return new Promise(resolve => {
      this.http.get(this.apiSection+'?StreamId='+streamId+'&MediumId='+mediumId+'&StandardId='+standardId).subscribe(data => {
        resolve(data);
        console.log(data);
        console.log(this.apiSection+'?StreamId='+streamId+'&MediumId='+mediumId+'&StandardId='+standardId);
      }, err => {
        console.log(err);
      });
    });
  }

  getStudentAttendanceList(streamId, mediumId, standardId, sectionId) {
    return new Promise(resolve => {
      this.http.get(this.apiStudentList+'?StreamId='+streamId+'&MediumId='+mediumId+'&StandardId='+standardId+'&SectionId='+sectionId).subscribe(data => {
        resolve(data);
        console.log(data);
      }, err => {
        console.log(err);
      });
    });
  }

  postStudentAttendanceDetails(streamId, mediumId, standardId, sectionId, id, name) {
    return new Promise(resolve => {
      this.http.post('http://localhost:49379/api/Attendance/PostStudentAttendance', {
        "Student_Id": id,
        "Student_Name": name,
        "Attendance_Status": 1,
        "section_Id": '10',
        "Date": 15/10/2018
      }).subscribe(data => {
        resolve(data);
      }, err => {
        console.log(err);
      });
    });
  }

```

How to Send these all student data to the database?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [October 15, 2018, 9:21pm UTC](https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577/2 "2018-10-15T21:21:08Z")

</div>

I’m not really sure what you’re asking, but a couple of things that should improve matters:

Please get rid of all the `Promise` stuff in your provider. Instead simply return the `Observable`s that `http` gives you, and declare that fact in the method signatures:

```auto
export interface AttendanceMedium {
// stuff in here
}
getStudentAttendanceMediumDetails(id: string): Observable<AttendanceMedium[]> {
  return this.http.get<AttendanceMedium[]>(this.apiMedium, new HttpParams().set('Id', id));
}

```

Secondly, it looks like you are trying to populate the options of one `select` based on a choice made in another. This is harder than it should be, and you might want to see [this post](https://forum.ionicframework.com/t/how-to-get-data-in-to-select-in-the-form-coontrol/84349/2?u=rapropos).

---

<div class="post-metadata">

**Author:** ![M014](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@M014](https://forum.ionicframework.com/u/M014)\
**Post date:** [October 16, 2018, 4:32am UTC](https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577/3 "2018-10-16T04:32:29Z")

</div>

> [@rapropos](#):
>
> I’m not really sure what you’re asking

My point is I need to post all these values (including toggle changed value) of each student to the database.

I am selecting options value in the different table from the database( i need to select the options based on the first selected option value).

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:13pm UTC](https://forum.ionicframework.com/t/send-multiple-data-to-database-using-rest-api-in-ionic3/144577/4 "2021-07-19T21:13:13Z")

</div>

Closed on July 19, 2021, 9:13pm UTC


