1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    8
    Vote Rating
    0
    MiceneSagitter is on a distinguished road

      0  

    Default Help passing STRING array to PHP

    Help passing STRING array to PHP


    Hello everybody, I'm a newby on ExtJs but I've managed to overcome many problems reading forums and posts.

    Now I have a little problem using a method POST.....and trying to pass array as params. But the real problem is due to String Array.........I explain...

    I have a JsonStore

    Code:
    var store_clienti = new Ext.data.JsonStore({
             url: 's_find_clienti.php',
             root: 'data_root',
             fields: ['id','livello','nome'],
             autoLoad:true,
             autoDestroy: false
             });
    Ok, now I made a function like that :

    Code:
    function esporta_griglia(store){
             
             var array_id = new Array();
             var array_livelli = new Array();
             var array_nomi = new Array();
    
             var i = 0;         
             store.each(function(record){
                   array_id[i] = parseInt(record.get('id'));
                   array_livelli[i] = record.get('livello');
                   array_nomi[i] = record.get('nome');
                   i++;
                });
    
             Ext.Ajax.request({            
                url: 's_prova.php',
                params: {sarray_id:Ext.encode(array_id), sarray_livelli:Ext.encode(array_livelli), sarray_nomi:Ext.encode(array_nomi)}
                method: 'POST',
                success: function(result){
                      window.open('griglia.txt','nuovapagina','width=700,height=600');
                },
                      failure: function() {
                      Ext.Msg.alert('Connection not executed!');
                   }
                });


    Ok, now the PHP script is this:


    Code:
    <?php
    include("../common/common_php_header.php");
    
    
    $array_id = array();
    $array_livelli = array();
    $array_nomi = array();
    
    
    
    
    
    
    $array_id = json_decode($_POST['sarray_id']);
    $array_livelli = json_decode($_POST['sarray_livelli']);
    $array_nomi = json_decode($_POST['sarray_nomi']);
    
    
    $identificatore = fopen("griglia.txt","w");
    
    
    // Scrivo i dati nel file
    fwrite($identificatore, $array_id[0]);
    fwrite($identificatore, "---");
    fwrite($identificatore, $array_livelli[0]);
    fwrite($identificatore, "---");
    fwrite($identificatore, $array_nomi[0]);
    fclose($identificatore);
    
    
    ?>

    What I pass with the encode method is this:

    • sarray_id:
      [11,782,588,682,781,683,385,384,263,157,54,60,350,352,386,387,589,70,324,608,193,71,65,413,272,194,393,440,195,273]
    • sarray_livelli:
      [3,2,1,0,1,0,1,1,2,3,1,1,1,2,1,2,0,0,2,1,2,0,2,1,0,0,2,2,0,0]
    • sarray_nomi:
      ["something","something2","something3","something4",..........and so on]




    And the result in the .txt file is this:

    11---3---
    As you can imagine I've a problem with the array encode/decode methods.

    For numeric arrays everything is fine, but with the string array I cannot decode it properly....





    Could you please help me with this problem. Any suggest will be useful.

    Thanks and sorry for my english....

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,639
    Vote Rating
    400
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    I use this approach ...

    Code:
    var records = [];
    if (data.records.length){
        for (var i = 0; i < data.records.length; i++){
            records.push(
                {
                    marc_tag: data.records[i].data.marc_tag,
                    marc_info: data.records[i].data.marc_info,
                    marc_data: data.records[i].data.marc_data,
                    marc_subfields: data.records[i].data.marc_subfields,
                    sub_occurrence: 1
                }
            );
        }
    
        // make call to server with selected ids
        Ext.Ajax.request({
            method: 'POST',
            url: 'index.php/mapper/update_profile/',
            params  : {
                recs: Ext.encode(records)
            },
            success: function() {
            },
            failure: function() {
            }
        });
    }
    
    
    
    // PHP :: model
    function update_profile($file, $recs = NULL)
    {
        // code from controller ...here for reference
        $recs = $this->input->get_post('recs', TRUE); // get id list
        $recs = json_decode($recs);
    
    ..
    
        // no need to set table name, insert perform this
        if ($recs) {
            foreach ($recs as $rec) {
               // perform action here
            }
            return array('success' => TRUE);
        } else { return array('success' => FALSE); }
    }
    Regards,
    Scott.

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar