嗨我想从mysql数据库中获取值以在UITextField中显示值。 这里我的PHP编码
<?php
$host = "localhost";
$user = "xcode";
$pass = "xcode";
$db="xcode";
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
echo mysql_get_server_info() . "\n";
$r2 = mysql_select_db($db);
if (!$r2) {
echo "Cannot select database\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "database selected\n";
}
$sql="select address,phone from login where name='{$_GET['name']}'";
if(!mysql_query($sql))
{
trigger_error(mysql_error(), E_USER_ERROR);
}
else
{
echo"1 record added";
}
mysql_close();
?>
这里是我的Xcode
- (IBAction)find:(id)sender {
NSString *strURL=[NSString stringWithFormat:@"http://192.168.1.12:81/priya/sam.php?name=%@",name.text];
NSData *dataURL=[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult=[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@",strResult);
}
我想在故事板中的文本字段中显示地址和电话。
答案 0 :(得分:0)
回答我的问题..
- (IBAction)find:(id)sender
{
NSError *err;
NSString *strURL=[NSString stringWithFormat:@"http://192.168.1.6:81/priya/sam.php?"];
NSString *aa=name.text;
NSData *dataURL=[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataURL options: kNilOptions error:&err];
NSMutableArray *array1=[[NSMutableArray alloc]init];
array1=[jsonArray objectForKey:@"key"];
NSLog(@"%@",array1);
for(int i=0;i<(array1.count);i++)
{
NSString *bb=[[array1 objectAtIndex:i]objectForKey:@"firstName"];
if([bb isEqualToString:aa])
{
address.text=[[array1 objectAtIndex:i]objectForKey:@"firstName"];
phone.text=[[array1 objectAtIndex:i]objectForKey:@"lastname"];
}
}
}
感谢所有