我对 obj-c 很陌生,我正在做这个应用程序,您可以在其中单击注释,将您带到该国。我想使用外部 php 脚本连接到 MySql:
<?php
include("connect.php");
$land = $_GET['land'];
$res = mysql_query("SELECT * FROM lande WHERE name = '$land'");
$row = mysql_fetch_array($res);
$flag = $row['flag'];
echo $flag;
echo $land;
?>
这是我在 Xcode 中的按钮:
-(void)button:(id)sender {
if (mapView.selectedAnnotations.count == 0)
{
//no annotation is currently selected
return;
}
id<MKAnnotation> selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];
country_title = selectedAnn.title;
UIViewController* Countries = [[UIViewController alloc] initWithNibName:@"Countries" bundle:[NSBundle mainBundle]];
NSString *strUrl = [NSString stringWithFormat:@"http://localhost:8888/app/country.php?land=%@",country_title];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@",strResult);
[self.view addSubview:Countries.view];
}
如何打印我的结果?这完全合法吗?应用商店会允许吗?还有另一种方法吗?我知道 SQLite,但似乎很难...... :(