Php 连接到mysql数据库的iOS不显示新行
我有这段代码,它从MySQL数据库检索用户的名字。但是,它不会加载我刚刚放入数据库的新条目Php 连接到mysql数据库的iOS不显示新行,php,ios,mysql,objective-c,Php,Ios,Mysql,Objective C,我有这段代码,它从MySQL数据库检索用户的名字。但是,它不会加载我刚刚放入数据库的新条目 -(void) fetchUsers { @try { NSURL * url = [NSURL URLWithString:@"http://malaebna.com/usersMalaebna.php"]; NSData *data = [NSData dataWithContentsOfURL:url]; NSMutableArray
-(void) fetchUsers {
@try
{
NSURL * url = [NSURL URLWithString:@"http://malaebna.com/usersMalaebna.php"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSMutableArray *jsonArray2 = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
preCalcArray = [[NSMutableArray alloc] init];
for (int i = 0; i < jsonArray2.count; i++) {
NSString *mEmail = [[jsonArray2 objectAtIndex:i] objectForKey:@"email"];
NSString *mPass = [[jsonArray2 objectAtIndex:i] objectForKey:@"password"];
NSString *mNumber = [[jsonArray2 objectAtIndex:i] objectForKey:@"number"];
NSString *mReservations = [[jsonArray2 objectAtIndex:i] objectForKey:@"reservations"];
NSLog(mEmail);
NSLog(mPass);
[preCalcArray addObject:[[users alloc] initWithEmail:mEmail andPassword:mPass andNumber:mNumber andReservations:mReservations]];
//[self.tableView reloadData];
}
}
@catch (NSException *ex) {
}
}
-(void)fetchUsers{
@试一试
{
NSURL*url=[NSURL URLWithString:@”http://malaebna.com/usersMalaebna.php"];
NSData*data=[NSData dataWithContentsOfURL:url];
NSMutableArray*jsonArray2=[NSJSONSerialization JSONObjectWithData:数据选项:编织错误:nil];
precarray=[[NSMutableArray alloc]init];
for(int i=0;i
例如,我有一个创建帐户页面,我将创建一个帐户exampleemail@gmail.com.
它将成功地插入数据库
-(void) fetchUsers {
@try
{
NSURL * url = [NSURL URLWithString:@"http://malaebna.com/usersMalaebna.php"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSMutableArray *jsonArray2 = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
preCalcArray = [[NSMutableArray alloc] init];
for (int i = 0; i < jsonArray2.count; i++) {
NSString *mEmail = [[jsonArray2 objectAtIndex:i] objectForKey:@"email"];
NSString *mPass = [[jsonArray2 objectAtIndex:i] objectForKey:@"password"];
NSString *mNumber = [[jsonArray2 objectAtIndex:i] objectForKey:@"number"];
NSString *mReservations = [[jsonArray2 objectAtIndex:i] objectForKey:@"reservations"];
NSLog(mEmail);
NSLog(mPass);
[preCalcArray addObject:[[users alloc] initWithEmail:mEmail andPassword:mPass andNumber:mNumber andReservations:mReservations]];
//[self.tableView reloadData];
}
}
@catch (NSException *ex) {
}
}
但是,当我返回登录页面并获取用户时,不会获取新条目
我将不得不等待或刷新我的chrome浏览器上的PHP页面,以便它出现在应用程序中
这是我的php获取脚本:
<?php
// Create connection
$con = new mysqli("localhost","","","");
$con ->set_charset("utf8");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT * FROM users";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray, JSON_UNESCAPED_UNICODE);
}
// Close connections
mysqli_close($con);
?>
我急需帮助。
$temparray
毫无意义$row
已经是一个数组,您所做的只是做一个冗余拷贝$resultaray[]=$row
是存储该行所需的全部内容。我刚刚尝试了它,但仍然不会加载新条目,除非我刷新,尽可能将纯文本作为文本而不是图像发布。这使得在任何可能的解决方案中重复使用变得更加困难。很抱歉,我是新来的,请注意,谢谢。$temparray
毫无意义$row
已经是一个数组,您所做的只是做一个冗余拷贝$resultaray[]=$row
是存储该行所需的全部内容。我刚刚尝试了它,但仍然不会加载新条目,除非我刷新,尽可能将纯文本作为文本而不是图像发布。这使得在任何可能的解决方案中重复使用变得更加困难。对不起,我是新来的,请注意,谢谢。