0

Hi ya'll I am building an app and I trying to get data to display on my app via MySQL and PHP.

I have looked at some tutorials and I tried to make sense of them and this what I have come up with...

This is my php file which is located on my server GetData.php

$mysqli = new mysqli("myhostingserver", "username", "password", "database");
$result = $mysqli->query("SELECT id, CASE open when 1 then 'Yes' when 0 then 'No' END as open, date, time, extra1, extra2, lastUpdated FROM MyTable");

and this is what I put on my ViewController.h file in xcode

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (retain, nonatomic) IBOutlet UILabel *YesOrNo;

@end

and this is the code from my ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *strURL = [NSString stringWithFormat:@"http://myhostingserver.com/GetData.php"];

    // to execute php code
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

    // to receive the returend value
    NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_YesOrNo release];
    [super dealloc];
}
@end

I think this seems right, but how do I get the data of open in the textbox?

would it be something along the lines of *YesOrNow = *strResult['open']?

I ran my app with the code above, no errors just a warning that says *strResult is an unused variable...please help

1 Answer 1

1

Set the text of the YesOrNo label to the strResult variable you created from the network script: self.YesOrNo.text = strResult;

Seems that you're jumping very quickly into app and server interactions. slow down and learn about PHP, and Objectice-C/Cocoa-touch separately so you can more easily identify what to do and debug on your own. i'd say this question is somewhat a waste and such a problem would normally be solved given basic knowledge of application(ios) development

Sign up to request clarification or add additional context in comments.

3 Comments

First I had to have my php files echo out the value and then I applied self.YesOrNo.text = strResult; and it worked! My question is I am planing on having more than one label that I will want to display more data from the sql select statment $result = $mysqli->query("SELECT id, CASE open when 1 then 'Yes' when 0 then 'No' END as open, date, time, extra1, extra2, lastUpdated FROM MyTable");
Is there away to pick which data I want from the sql statement like self.YesOrNo.text = strResult['open'] or self.YesOrNo.text = strResult['lastUpdated'] or will I have to write a new php file for each data I want to display?
@user2499454 use a dictionary to contain the value you get from the server, then for each label, assign the value from your dictionary to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.