1. #1
    Sencha User
    Join Date
    Jan 2008
    Posts
    66
    Vote Rating
    0
    mnask is on a distinguished road

      0  

    Default save data store to database

    save data store to database


    hi there ,
    i have store in editableGrid , so i want to save updated data in store to database using php
    i have no idea ,, could u tell me how plz

    i dont know how to send the store date to php page to decode it .. then save it in database

    i hope u got me

    anyway .. thanks,

    my regards

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    The easiest method is:

    Code:
    var records = store.getModifiedRecords();
    var data = [];
    for (var i = 0; i < recs.length; i++) {
    	data[i] = records[i].data;
    }
    Ext.Ajax.request({
    	url: 'myurl',
    	jsonData: data
    });
    The data of the changed records will be in JSON format, so you'll have to decode it on the server.

  3. #3
    Sencha User
    Join Date
    Jan 2008
    Posts
    66
    Vote Rating
    0
    mnask is on a distinguished road

      0  

    Default


    getModifiedRecords ,, what is it

    i have an error
    mystoreName.getModifiedRecords is not function !!

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Are you sure you didn't make a typo somewhere (see API docs) ?

  5. #5
    Sencha User
    Join Date
    Jan 2008
    Posts
    66
    Vote Rating
    0
    mnask is on a distinguished road

      0  

    Default


    im sorry man , its working

    but my question now ,, how to get the what i want to decode

    i mean in php

    json.decode(?????) decode what ?
    how to get the parameter

  6. #6
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    Have you looked at my example? There's two other examples in the forums as well. There's also a new tutorial on this as well.

  7. #7
    Sencha User
    Join Date
    Jan 2008
    Posts
    66
    Vote Rating
    0
    mnask is on a distinguished road

      0  

    Default


    hi again ,

    at server side i got this data by using php ... print_r()

    ArrayArray

    (

    [0] => stdClass Object

    (

    [symbol] => ABCO

    [market_desc] => Amman Stock Exchange

    [description] => ARAB BANKING CORPORATION /(JORDAN)

    [showIn] => Watchlist

    [change] =>

    [delete] => delete

    [ticker_id] => 50

    )

    )

    how to get the data ??

  8. #8
    Ext User
    Join Date
    Jun 2007
    Posts
    187
    Vote Rating
    1
    anjelika is on a distinguished road

      0  

    Default


    Quote Originally Posted by mnask View Post
    hi again ,

    at server side i got this data by using php ... print_r()

    ArrayArray

    (

    [0] => stdClass Object

    (

    [symbol] => ABCO

    [market_desc] => Amman Stock Exchange

    [description] => ARAB BANKING CORPORATION /(JORDAN)

    [showIn] => Watchlist

    [change] =>

    [delete] => delete

    [ticker_id] => 50

    )

    )

    how to get the data ??
    You will have to iterate trough all your received records (there can be more than 1) and update your datdabase.
    Something like this, in your case:
    PHP Code:
    $data $_POST['data']; //retreive the posted data
    foreach ($data as $row) {
     
    $id $row[0]['ticker_id'];
     
    $description $row[0]['description'];
     
    $sql "UPDATE my_table SET description = $description WHERE id = $id";
     
    mysql_query ($sql) or die mysql_error(); //execute the query and retreive the potential error


  9. #9
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    Just wondering if you could maybe generalize that a bit without having to specify the keys explicitly. I haven't done this, and wrote this here, so may (probably ) not work:

    PHP Code:
    $encodedData $_POST['records']; //retrieve the records to be updated from the posted data
    $records decodeData($encodedData);//use whatever decode procedure

    //loop through each record sent
    foreach ($records as $record) {
        
        
    $id $record['id'];//assume each record id stored in 'id'    
        
    $key_value '';//initialize

        //loop through each changed field for each record
        //assume rest of altered record data is in 'data'
        
    foreach($record['data'] as $key => $value){
            
    $key_values "$key=$value,";
        }

        
    $key_value rtrim$key_values',' );

        
    $where_condition "id = $id";
        
    $row_count 1;

        
    $sql "UPDATE tbl_name SET $field_values WHERE $where_condition LIMIT $row_count";

        
    $result mysql_query ($sql); //execute the query
        
        
    if ($result$count++;//so can send back number of successfully updated records if we want
    }  

    $o = array();
    $o["count"] = $count;

    if (
    $count 0) {
        
    $o["success"] = true;
    } else {
        
    $o["success"] = false;
    }

    echo 
    encodeData($o);//use whatever routine to encode JSON