我爲iPhone創建了一個工作應用程序,它通過PHP頁面從MYSQL數據庫獲取數據,然後在UIWebView中打印數據。在cocoa-touch中通過PHP使用MYSQL數據?
但是這裏的問題是我不想再在UIWebView中打印數據,我想要檢索數據並將其拉回到應用程序中,以將UILabel.text更改爲MYSQL數據。
我現在有以下(其中數據打印到一個UIWebView(不包括最代碼由於DB連接密碼等)):
PHP FILE:
// Localize the GET variables
$name = isset($_GET['name']) ? $_GET['name'] : "";
// Protect against sql injections
$name = mysql_real_escape_string($name);
$cash = "SELECT cash FROM t_users WHERE username='$name' LIMIT 1";
$result = mysql_query($cash,$conn);
if(!$result) {
die("Error retrieving scores " . mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head>
<body>
<?php
// Display the table
while ($row = mysql_fetch_object($result)) {
echo ''.$row->cash.'';
}
mysql_free_result($result);
mysql_close($conn);
?>
</body>
</html>
PlayerInfo.m
-(IBAction)refreshData:(id)sender {
test1AppDelegate *mainDelegate = (test1AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString * login_key = @"REMOVED FOR STACKOVERFLOW";
NSString * username = [mainDelegate.currentUser stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"REMOVED FOR STACKOVERFLOW/put_score.php?login_key=%@&name=%@",
login_key,username];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:requestObj];
}
這個變化顯示了在webvi中的球員現金新手,但我想更改UILabel以顯示現金數字。
請幫忙?
謝謝!
這是可能的...看看我下面的評論。 – Remover 2011-05-27 21:52:31