PHP服务器问题


jsonFile PHP server problems

我试图得到一些服务器数据转储到我的iphone表。流程是标准的server - php_interface - iOS。我正在尝试echo json_encode(array)设置,但是当这样做时,我无法填充数组,因此(在堆栈用户的出色帮助下)我切换了设置并放弃了json_encode(数组)设置。但是我现在意识到我需要它来连接iOS。我想只是简单地输入它在我当前的PHP代码结束,但这似乎不工作。我很有信心在iOS方面的代码正在工作,因为构建显示了一个数组,它根本没有填充,我在xCode中得到的错误信息是说它找到了0行。帮助吗?

当前代码(我正在尝试工作):

        $mysqli = mysqli_connect($dbHOST, $dbUSER, $dbPASS, $dbNAME);
        $query = "SELECT Name, Address, Latitude, Longitude FROM Locations";
        $result = mysqli_query($mysqli, $query);
        if($result) {
            while ($row = mysqli_fetch_assoc($result)) {
                echo 'Name: ' . $row['Name'] . '<br />';
                echo 'Address: ' . $row['Address'] . '<br>';
                echo 'Latitude: ' . $row['Latitude'] . '<br>';
                echo 'Longitude: ' . $row['Longitude'] . '<br>';    
                echo ''. '<br>';
    json_encode($result);
            }
        }

不能完全工作的旧代码片段:

    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $sql = "SELECT * FROM `Locations` ";
    if ($result = mysqli_query($con, $sql))
    {
     $resultArray = array();
     $tempArray = array();
     while($row = $result->fetch_object(Locations)){
      $tempArray = $row;
        array_push($resultArray, $tempArray);
     }
     echo json_encode($resultArray);
    }
    // Close connections
    mysqli_close($con);
    ?>

xCode获取行的方法:

    - (void) downLoadItems{
        // Download the json file
        NSURL *jsonFileUrl = [NSURL URLWithString:@"http://server.com/service.php"];
        // Create the request
        NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:jsonFileUrl];
        // Create the NSURLConnection
        [NSURLConnection connectionWithRequest:urlRequest delegate:self];
    }

我搞砸了,只是在PHP方法中解析了位置。删除它,"旧"代码就可以正常工作了。