Php 使用行内容创建NSArray(MySQL)
我想创建一个包含MySQL表行内容的NSArray witch 我使用php脚本获取数据Php 使用行内容创建NSArray(MySQL),php,iphone,mysql,objective-c,nsarray,Php,Iphone,Mysql,Objective C,Nsarray,我想创建一个包含MySQL表行内容的NSArray witch 我使用php脚本获取数据 $response = $bdd->query('SELECT * FROM iPhoneTests'); while ($datas = $response->fetch()) { ?> <array> <integer><?php echo $datas['Temperature']; ?></integer>
$response = $bdd->query('SELECT * FROM iPhoneTests');
while ($datas = $response->fetch())
{
?>
<array>
<integer><?php echo $datas['Temperature']; ?></integer>
</array>
<?php
}
当我在我的网络浏览器中测试时,我会得到所有数据,但在我的应用程序中,使用NSlog我只会得到第一个值
我对这个问题已经讨论了好几次了,但我不能成功
如果有人看到我的错误,请告诉我您正在为每一行创建一个数组(顺便说一句,这是无效的,因为这些数组也必须嵌套到一个数组中) 这样做:
$response = $bdd->query('SELECT * FROM iPhoneTests');
?><array><?
while ($datas = $response->fetch())
{
?>
<integer><?php echo $datas['Temperature']; ?></integer>
<?
}
?></array>
$response=$bdd->query('SELECT*fromiPhoneTests');
?>
您正在为每一行创建一个数组(顺便说一句,这是无效的,因为这些数组也必须嵌套到一个数组中)
这样做:
$response = $bdd->query('SELECT * FROM iPhoneTests');
?><array><?
while ($datas = $response->fetch())
{
?>
<integer><?php echo $datas['Temperature']; ?></integer>
<?
}
?></array>
$response=$bdd->query('SELECT*fromiPhoneTests');
?>
我们可以通过多种方式与服务器通信。我建议通信数据只能是字符串格式,一种方法是使用JSON,您可以从这里获得JSON解析器,解释如下:
- (无效)连接:(NSURLConnection*)连接接收方响应: (NSURLResponse*)响应{ [接收数据集长度:0]; } //接收数据为NSMutableData ref
- (void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据{ [接收数据附录数据:数据]; }
- (无效)连接IDFinishLoading:(NSURLConnection*)连接{ //json数据检索完成(收到的数据为NSMutableData) 如果(接收数据==nil | |[接收数据长度]==0){ //获取响应时出现句柄错误,可能没有网络 [self-ShowAlertViewWith title:@“无网络”和Message:@“无法打开网络” 页,因为找不到internet连接。“andTag:0]; 返回; } NSString*ResponseBy=[[[NSString alloc]initWithData:receivedData 编码:NSUTF8StringEncoding]自动释放]; ////NSLog(responseBody); N错误*jsonParsingError=[[N错误分配]初始化]自动释放]; NSDictionary*jsonData=[NSDictionary Dictionary WithJSONDATA: [响应库数据使用编码:NSUTF8StringEncoding] 错误:&jsonParsingError] NSDictionary*serverError=[jsonData objectForKey:@“error”]==[NSNull null]? nil:[jsondataobjectforkey:@“error”] if(serverError==nil | |[serverError count]==0){ //没有发现其他错误 NSDictionary*response=[jsonData objectForKey:@“response”]=[NSNull null]? nil:[jsondataobjectforkey:@“response”]; NSArray*数组=[response objectForKey:@“数组”]==[NSNull null]?无: [response objectForKey:@“array”]; //我留下的代码不完整,这只是为了理解
如果您需要进一步解释,请告诉我。我们可以通过多种方式与服务器进行通信。我建议通信数据应仅为字符串格式,一种方式是使用JSON,您可以从这里获得JSON解析器,解释如下:
- (无效)连接:(NSURLConnection*)连接接收方响应: (NSURLResponse*)响应{ [接收数据集长度:0]; } //接收数据为NSMutableData ref
- (void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据{ [接收数据附录数据:数据]; }
- (无效)连接IDFinishLoading:(NSURLConnection*)连接{ //json数据检索完成(收到的数据为NSMutableData) 如果(接收数据==nil | |[接收数据长度]==0){ //获取响应时出现句柄错误,可能没有网络 [self-ShowAlertViewWith title:@“无网络”和Message:@“无法打开网络” 页,因为找不到internet连接。“andTag:0]; 返回; } NSString*ResponseBy=[[[NSString alloc]initWithData:receivedData 编码:NSUTF8StringEncoding]自动释放]; ////NSLog(responseBody); N错误*jsonParsingError=[[N错误分配]初始化]自动释放]; NSDictionary*jsonData=[NSDictionary Dictionary WithJSONDATA: [响应库数据使用编码:NSUTF8StringEncoding] 错误:&jsonParsingError] NSDictionary*serverError=[jsonData objectForKey:@“error”]==[NSNull null]? nil:[jsondataobjectforkey:@“error”] if(serverError==nil | |[serverError count]==0){ //没有发现其他错误 NSDictionary*response=[jsonData objectForKey:@“response”]=[NSNull null]? nil:[jsondataobjectforkey:@“response”]; NSArray*数组=[response objectForKey:@“数组”]==[NSNull null]?无: [response objectForKey:@“array”]; //我留下的代码不完整,这只是为了理解