![](/img/trans.png)
[英]PHP & MYSQL. Want to display first image of directory. Directory path from the database
[英]iOS, PHP and mySQL. Display data from a database on Iphone
嗨,我正在构建一个应用程序,我试图通过MySQL和PHP使数据显示在我的应用程序上。
我看过一些教程,我试图弄明白它们,这就是我想出的...
这是我的php文件,位于我的服务器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");
这就是我在xcode中放在ViewController.h文件中的内容
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *YesOrNo;
@end
这是我的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
我认为这似乎是正确的,但是如何在文本框中获取打开数据?
会像*YesOrNow = *strResult['open']
吗?
我使用上面的代码运行了我的应用,没有错误,只是警告说* strResult是一个未使用的变量...请帮助
将YesOrNo
标签的文本设置为您通过网络脚本创建的strResult
变量: self.YesOrNo.text = strResult;
似乎您正在迅速进入应用程序和服务器交互。 放慢脚步,分别了解PHP和Objectice-C / Cocoa-touch,以便您更轻松地确定要做什么并自行调试。 我会说这个问题有点浪费,考虑到应用程序(iOS)开发的基本知识,通常可以解决此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.