Hello guys, I have a problem when I’m displaying information without id, it’s work fine. But , I’m adding id to the SQL command (“SELECT * FROM tb_case WHERE id = ‘$postjson[id]’ ORDER BY casename DESC LIMIT $postjson[start],$postjson[limit]”), it said that “Undefined index: id in fyp\api\process.php on line 140 {“success”:true,“result”:}”
the other page works fine but this page is undefined.
Am I doing anything wrong ?
This code is inside mycase.ts
import { resolve } from 'url';
import { LoadingController, ToastController } from '@ionic/angular';
import { AccessProviders } from 'src/app/providers/access-providers';
import { Storage } from '@ionic/storage';
@Component({
selector: 'app-mycase',
templateUrl: './mycase.page.html',
styleUrls: ['./mycase.page.scss'],
})
export class MycasePage implements OnInit {
cases: any = [];
limit: number = 13;
start: number = 0;
datastorage: any;
id: string;
constructor(
private loadingCtrl: LoadingController,
private accesspvdr: AccessProviders,
private toastCtrl: ToastController,
private storage: Storage,
) { }
ngOnInit() {
}
ionViewDidEnter() {
this.storage.get('storage_xxx').then((val) => {
this.datastorage = val;
this.id = this.datastorage.id;
});
this.start = 0;
this.cases = [];
this.loadCase();
}
async presentToast(a) {
const toast = await this.toastCtrl.create({
message: a,
duration: 1500,
position: 'top'
});
toast.present();
}
async doRefresh(event) {
const loader = await this.loadingCtrl.create({
message: 'Please wait . . .',
});
loader.present();
this.ionViewDidEnter();
event.target.complete();
loader.dismiss();
}
loadData(event) {
this.storage.get('storage_xxx').then((val) => {
this.datastorage = val;
this.id = this.datastorage.id;
});
this.start += this.limit;
setTimeout(() => {
this.loadCase().then(() => {
event.target.complete();
});
}, 500);
}
async loadCase() {
return new Promise(resolve => {
const body = {
act: 'loadCase',
id: this.id,
start: this.start,
limit: this.limit
};
this.accesspvdr.postData(body, 'process.php').subscribe((res: any) => {
for (const datas of res.result) {
this.cases.push(datas);
}
resolve(true);
});
});
}
async delCase(a) {
return new Promise(() => {
const body = {
act: 'delCase',
casename: a,
};
this.accesspvdr.postData(body, 'process.php').subscribe((res: any) => {
if (res.success === true) {
this.presentToast('Delete Successful');
this.ionViewDidEnter();
} else {
this.presentToast('Delete Unsuccessful');
}
});
});
}
}
mycase.html
<ion-header>
<ion-toolbar color="success">
<ion-title>My Case</ion-title>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-refresher slot="fixed" (ionRefresh)="doRefresh($event)">
<ion-refresher-content pullingIcon="arrow-down-outline"></ion-refresher-content>
</ion-refresher>
<ion-list>
<ion-item-sliding *ngFor="let case of cases">
<ion-item>
<ion-label>{{ case.casename }}</ion-label>
</ion-item>
<ion-item-options side="end">
<ion-item-option (click)="openCrud(case.casename)" color="primary">Update</ion-item-option>
<ion-item-option (click)="delCase(case.casename)" color="danger">Delete</ion-item-option>
</ion-item-options>
</ion-item-sliding>
</ion-list>
</ion-content>