0

I'd like to populate an NSArray for a Picker from my database. I'm using this code at the moment:

NSArray *arrayToLoadPicker = [[NSArray alloc] initWithObjects:@"Data1", @"Data2", @"Data3", nil];

I wrote a PHP script on my server and this code returns an array (this seemed the most logical way to deal with it, to me). How can I populate said NSArray with the elements given by the script? I use a MySQL database.

Thank you guys

3
  • 1
    How do you access you php script? What exactly does your php script output? Commented Nov 25, 2011 at 13:29
  • 2
    Simplest thing to do is to use an NSMutableArray and write a loop to read from your MySQL output and insert into the array. Commented Nov 25, 2011 at 13:51
  • @eelco I create a NSURL with the URL of my script but then I don't know how to deal with it.<br />My PHP script is the following: $query = mysql_query("SELECT * FROM table"); while ($row = mysql_fetch_array($query)) { echo $row['field']; } Commented Nov 28, 2011 at 8:47

1 Answer 1

1

If your server is a web (http) server and your client is an iOS application, I'd recommend that your server returns the array in JSON format, and your client parses it with some JSON framework. Native JSON support in iOS?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.