Retrieving multiple objects from Storage


#1

Hi guys I am building a page to send some user inputted information into the database of the server.

I have some product id’s in my Storage.
contact

Like I mentioned in the comments when I use for loop I am able to see every ‘id’ saved in the storage.
but when I exit from the ‘for loop’ the only value I get in my ‘this.id’ is the last id in the storage.

please give me any advice or suggestion in getting multiple id’s into a variable, so that it can be pass along to a function which sends data to the database of the server.


#2

Just create array like shown below.

this.id = [];
this.storage.get("cart").then((data)=>{
     this.cartItems=data;
     if(data.length>0){
         for(let i=0; i<data.length; i++){
              this.id.push(data[i].product.id);
         }
     console.log(this.id);
    }
});

#3

@Ankit_Makwana Great it worked, thankyou.

I am trying to insert a list of data to a table I created in database. I’m thinking of using php for data insertion but so far I haven’t come across any good documentation that I could understand…

Can you give advice / suggestion on what to do or where to look for data insertion using php.


#4

Sorry, I don’t know about PHP for inserting data.
But, there is good doc to add data in database with ionic storage. (where you can use indexeddb, sqlite or websql)
http://ionicframework.com/docs/storage

Btw there is one blog post which might help you.
http://masteringionic.com/blog/2016-12-15-using-php-and-mysql-with-ionic/