Hybrid View

  1. #1
    Sencha User roymj88's Avatar
    Join Date
    Nov 2011
    Location
    India
    Posts
    19
    Vote Rating
    0
    roymj88 is on a distinguished road

      0  

    Wink Unanswered: How to get values from database??

    Unanswered: How to get values from database??


    Hi,

    I am just exploring the sencha world.I am creating my first app using sencha. Can someone point me as to how i can get the data from the database using php and json. Ive got a code which i will write down.

    Code:
    function showRecent() {
                Ext.Ajax.request({
                    url: 'server.php?action=get',
                    success: function(e) {
                        var obj = Ext.util.JSON.decode(e.responseText);
                        var guests = obj.guests;					
                        if (guests) {						
                            var html = tpl.applyTemplate(guests);
                            Ext.getCmp('recentTab').update(html);
                        }
                    }
                });
            }
    Code:
    if (isset($_GET['action']) && $_GET['action'] == "get") {
            $sql = "SELECT * FROM messages";
            $guests = array();
            foreach ($dbh->query($sql) as $row)
            {
                $guests[] = array(
                    'id' => $row['id'],
                    'name' => $row['name'],
                    'email' => $row['email'],
                    'url' => $row['url'],
                    'message' => $row['message'],
                    'date' => $row['date_entry']
                );
            }
            echo json_encode(array('success' => true, 'guests' => $guests));
        }

    I am not able to get individual date from the array. Its always saying undefined.

    Also can i declare a global variable and use it throughout the project?

    I am creating a login page and using that information which i get from login, i need to fill up contents in the app. So i would need the id throughout. Or is it possible to send the value from one panel to another.

    Thanks

    Roy M J

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Answers
    130
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    as a first step: think about which framework you are using:
    Sencha Touch 1
    ST 2
    Ext JS 3
    Ext JS 4

    for example! then please use the matching forum(s) to ask questions there.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Answers
    130
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    do you have a success property set, like success:true inside of your JSON?
    if yes, post your json-serverresponse.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  4. #4
    Sencha User roymj88's Avatar
    Join Date
    Nov 2011
    Location
    India
    Posts
    19
    Vote Rating
    0
    roymj88 is on a distinguished road

      0  

    Default


    Hi,

    Thanks for replying..

    Sorry I am using secha touch 2.

    And yes i am setting success as true. But in the js file im not sure how to get values from the array.

    Code:
    echo json_encode(array('success' => true, 'guests' => $guests));
    The js part is as follows :

    Code:
    
    function showRecent() {
                Ext.Ajax.request({
                    url: 'server.php?action=get',
                    success: function(e) {
                        var obj = Ext.util.JSON.decode(e.responseText);
                        var guests = obj.guests;					
                        if (guests) {						
                            var html = tpl.applyTemplate(guests);
                            Ext.getCmp('recentTab').update(html);
                        }
                    }
                });
            }
    Many thanks

    Roy

  5. #5
    Sencha User roymj88's Avatar
    Join Date
    Nov 2011
    Location
    India
    Posts
    19
    Vote Rating
    0
    roymj88 is on a distinguished road

      0  

    Default


    What i would like to know is how i can get the individual values from variable guests. Till now i could not figure out how to get the values.

    Another thing is once i get the value will it be possible to declare it as a global variable so that i can use that value throughout the app?. Or is it good for me to use php session variablesfor this purpose.

    Thanks

    Roy

  6. #6
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Answers
    130
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    what do you get when logging the response, like:

    Code:
    success: function(response) {
        console.log(response.responseText);
    }
    global vars are a quite bad coding style.

    in general, after taking a closer look at your usecase.
    when you want to get an array of guests from your server,
    a single ajax call is not the best way to go.

    did you take a look at:
    http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store

    with using a store you can easily access your data, sort, filter, modify etc. it.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."