1

I have a database mysql and it contains 1000 records of people (Name, Age, Adress, Country). I want to make an application that :

  1. Randomly displays ONE of the records in the database.
  2. Randomly displays ONE of the records according to a specific 'Country'.

My usual approach to this is : parse ALL data to the iphone using JSON, then manipulate the data. Because of the volume of data that the user needs to download (1000 records) and because i only need just ONE of the records to be displayed, it seems wasteful to download all 1000 records and then sort the data. What other approach can i use? (not sure but is it possible to query the database directly?)

1 Answer 1

2

It would be very unsafe to query the DB directly and the usual approach you mentioned would be a very bad idea. So, the general approach, safe and optimized, for this scenario is to write some web-service, can be in PHP or ASP.net or etc., end-points which can optionally take some parameters, like the specific country, as argument and return you data in JSON format and then you can display it. This is how I'd approach to such problem. Here's a tutorial on writing some basic web-services with PHP.

http://davidwalsh.name/web-service-php-mysql-xml-json

Hope that'd help.

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

2 Comments

^^ also, what you are saying is : 1. To get only one record randomised, i can simply create a php script that returns a random record, however how would this work for the second part?. If the user has a specific country he wants to search for, i need to send the data from the iphone to the php script. Problem is, assuming there are muliple users, it would cause conflict no?
Conflict? why? you'd be passing the country information as a parameter in the GET request and the result will be delivered in the same very request. There'd be no confusion. In case of simultaneous users there could be bottleneck problem but there won't be conflicts. Hope I got your query correctly.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.