-
2 Apr 2008 3:34 AM #1
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 Apr 2008 3:38 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
The easiest method is:
The data of the changed records will be in JSON format, so you'll have to decode it on the server.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 });
-
2 Apr 2008 3:54 AM #3
getModifiedRecords ,, what is it
i have an error
mystoreName.getModifiedRecords is not function !!
-
2 Apr 2008 4:03 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
-
2 Apr 2008 4:17 AM #5
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
-
2 Apr 2008 7:06 AM #6
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.
MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
3 Apr 2008 2:18 AM #7
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 ??
-
3 Apr 2008 2:48 AM #8
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
}
-
3 Apr 2008 6:56 PM #9
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
MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow


Reply With Quote