php - iOS、PHP 和 mySQL。在 iPhone 上显示数据库中的数据

标签 php mysql ios

您好,我正在构建一个应用程序,并尝试通过 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)开发的基本知识,这样的问题通常可以解决

关于php - iOS、PHP 和 mySQL。在 iPhone 上显示数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17517740/

相关文章:

使用 .p8 文件后未收到 iOS Firebase 云消息通知

javascript - 如何使用backbone.js划分JSON集合结果

mysql - 如何统计sql数据库中每个单词的数量?

来自 Objective-C iPhone 应用程序的 PHP MySQL 请求未发布到我的表

MySQL 使用 if 语句从多个表中进行 SELECT

iphone - 如何在代码中而不是 Interface Builder 中设置 didEndOnExit?

iOS:是否可以同时从多个麦克风录音

php - 在 CodeIgniter Controller 中的任何其他方法之前运行一个方法

php - 如何使用 uploadify 传递表单值

PHP:在多个请求中保持与 API 的 HTTPS 连接打开