Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Display PHP data on Home View

$
0
0

I was wondering if someone could assist me please. How can I display data from a php page on my app. I currently able to do it but only on a table view, which when clicked displays the data on a Regular View page. I already tried to use the same code and just taking out the table part but I'm not able to do so. Here is an example of what I have on the table view.

staff.js

function Application_Staff() {
    //load component dependencies
    var activityIndicator;
    var employ_listing = Titanium.Network.createHTTPClient();
    var tbl_data = [];
    var array;
 
    //create component instance
    var self = Ti.UI.createWindow({
        navBarHidden : true,
        backgroundImage : "/bg.png",
    });
 
    var win = Ti.UI.createView({
        width : Ti.UI.FILL,
        height : Ti.UI.SIZE,
        top : 20,
        title : L('header_title'),
    });
 
    var topbar = Ti.UI.createView({
        width : Ti.UI.FILL,
        height : 50,
        top : 0,
        title : L('header_title'),
        backgroundImage : Ti.Filesystem.resourcesDirectory + "image/topbar.png",
    });
 
    var back_btn = Ti.UI.createButton({
        width : 60,
        height : 30,
        title:"Back",
        backgroundImage : Ti.Filesystem.resourcesDirectory + "image/button_image.png",
        left : 5,
        top : 10,
        font : {
            fontSize : 12
        },
 
    });
    back_btn.addEventListener('click', function() {
        self.close();
    });
 
    var header_title = Ti.UI.createLabel({
        color : 'white',
        font : {
            fontSize : 22
        },
        text : 'Staff Directory',
        textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER,
        top : 10,
        width : Ti.UI.SIZE,
        height : Ti.UI.SIZE
    });
 
    topbar.add(header_title);
    topbar.add(back_btn);
    win.add(topbar);
 
 
    var content_view = Ti.UI.createView({
        width : Ti.UI.FILL,
        height : '100%',
        top : 70,
    });
 
    var table = Titanium.UI.createTableView({
        backgroundImage : Ti.Filesystem.resourcesDirectory + "images/bg.png",
    });
 
    employ_listing.open("GET", 'http://www.mysite.com/staff.php');
    employ_listing.send();
    console.log("new");
    employ_listing.onload = function() {
 
        var res = JSON.parse(this.responseText);
        Ti.API.info('res@loginReq.onload:\n' + this.responseText)
        var LOGGED = Ti.App.Properties.getString('logged');
        array=res;
        for (var i = 0; i < res.length; i++) {
            var row = Ti.UI.createTableViewRow({
                width : Ti.UI.FILL,
                height : 40,
                backgroundDisabledColor : true,
                backgroundColor : "#8a8a8a",
            });
            var header_txt = Ti.UI.createLabel({
                top : 5,
                left : 10,
                text : res[i].person,
                font : {
                    fontSize : 14
                },
                color : 'white'
            });
            var detail_text = Ti.UI.createLabel({
                top : 20,
                left : 10,
                text : res[i].headline,
                font : {
                    fontSize : 12
                },
                color : 'white'
            });
            var image = Ti.UI.createImageView({
                image : Ti.Filesystem.resourcesDirectory + "image/arrow.png",
                right : 10
 
            });
            row.add(header_txt);
            row.add(detail_text);
            row.add(image);
 
            tbl_data.push(row);
        }
        // alternatively, you could do
        table.setData(tbl_data);
        activityIndicator.hide();
        content_view.add(table);
    }   
 
    employ_listing.onerror = function(e) {
        //Ti.App.fireEvent('server_error_msg');
        var alertDL = Ti.UI.createAlertDialog({
            title : L('error'),
            message : L('server_error_msg'),
            buttonNames : ['OK']
        });
        alertDL.show();
    }
 
 
    table.addEventListener('click', function(e) {
        var index = e.index;
 
        Ti.API.log('Row at index:' + index + " " +array[index].img1);
        Ti.App.Properties.setObject("staff_detail",array[index]);
 
 
        var osname = Ti.Platform.osname, version = Ti.Platform.version, height = Ti.Platform.displayCaps.platformHeight, width = Ti.Platform.displayCaps.platformWidth;
 
        var Window;
 
        if (osname === 'android') {
            Window = require('ui/handheld/android/Application_Staff_Detail');
        } else {
 
            Window = require('ui/handheld/Application_Staff_Detail');
        }
 
        new Window().open();
 
    });
 
var style;
if (Ti.Platform.name === 'iPhone OS'){
  style = Ti.UI.iPhone.ActivityIndicatorStyle.DARK;
}
else {
  style = Ti.UI.ActivityIndicatorStyle.DARK;
}
activityIndicator = Ti.UI.createActivityIndicator({
  color: 'white',
  font: {fontFamily:'Helvetica Neue', fontSize:26, fontWeight:'bold'},
  message: 'Loading...',
  style:style,
  top:'35%',
  left:"25%",
  height:Ti.UI.SIZE,
  width:Ti.UI.SIZE
});
 
    activityIndicator.show();
 
 
    content_view.add(activityIndicator);
    self.add(win);
    self.add(content_view);
    return self;
}
This passes the data to my Staff_Detail page.

How can I modify this so that I can display--

text : res[i].headline,

or array.headline on the Home Page View?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>