Alex
Alex

Reputation: 3072

Populating a TableView with data from MySQL Database using PHP

I will admit, I don't know much about PHP and have google'd around for an answer but haven't had much luck in finding anything to suit my needs. I have however managed to create a simple connection script and login/authentication script to my server for my iOS app. I have a table in the MySQL database which holds a list of events and was wondering what would be the best way to populate cells using the values from this table.

I already have the UITableView set up, and have managed to get it loading data from a local array all to the right places on the custom cell.

I am able to @echo the results of all of the table back, but what would be the best way to go about populating each cell with one row of the table?

Thanks!

Upvotes: 0

Views: 1632

Answers (1)

AlexeyVMP
AlexeyVMP

Reputation: 2426

It's good idea to use JSON to transfer data. PHP should have JSON support as well.

This is library for iPhone: https://github.com/stig/json-framework/

You need:

  1. Using PHP get data from the database
  2. Produce JSON-encoded array in PHP script
  3. Read this data using NSURLConnection on iOS device
  4. Parse received data from JSON to Obj-C objects (using the library above)

This is not so easy to learn fast, but there is a lot of examples in the Internet and this is good practice for sure. Learned once - helps forever.

Upvotes: 1

Related Questions