Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php从mysql获取值?_Php_Mysql_Ios - Fatal编程技术网

如何使用php从mysql获取值?

如何使用php从mysql获取值?,php,mysql,ios,Php,Mysql,Ios,您好,我正在尝试从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_

您好,我正在尝试从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();

?>
}


我想在故事板的文本字段中显示地址和电话

回答我的问题

 - (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"];
    }
   }

   }
-(iAction)查找:(id)发送方
{
n错误*错误;
NSString*strURL=[NSString stringWithFormat:@]http://192.168.1.6:81/priya/sam.php?"];
NSString*aa=name.text;
NSData*dataURL=[NSData datawithcontentsofull:[NSURL URLWithString:strURL]];
NSDictionary*jsonArray=[NSJSONSerialization JSONObjectWithData:dataURL选项:编织错误:&err];
NSMutableArray*array1=[[NSMutableArray alloc]init];
array1=[jsonArray objectForKey:@“key”];
NSLog(@“%@”,数组1);

对于(int i=0;i是否NSLog状态返回正确的值?那么您需要做的就是将其分配给
UITextField
,您可以为其创建一个IBOutlet,只需设置
UITextField
outlet的text属性,如
self.myTextField.text=strResult
您不应该使用
mysql\ucode>其弃用!
 - (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"];
    }
   }

   }