I have developed a webservice in PHP. It uses the MySQL database. In this, I have used JSON. I want to fetch data from this webservice in my iPhone app. I have used a function which has one parameter. How can I use this in the iPhone?
Webservice:
<?php
echo getdata($_REQUEST['lastupdate']);
function getdata($lastupdatedate){
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
//print $obj->{'foo-bar'}; // 12345
$con = mysql_connect("localhost","un","pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//print_r($con);
mysql_select_db("roster", $con);
$query = "select * from rates where LastUpdated = '".$lastupdatedate."' order by LastUpdated limit 1";
$rs = mysql_query($query) or die($query);
//print_r($rs);
while($row=mysql_fetch_assoc($rs)){
$record[] = $row;
}
$data = json_encode($record);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
return $data;
}
?>
I am requesting the URL: http://domain/t1.php?lastupdate=2012-09-01 01:00:00.
You would create an request for
http://domain/t1.php?lastupdate=2012-09-01 01:00:00and then parse your response JSON.Depending on how your code should function (onload or based on some user action) your code should function similar to this example from raywenderlich.com
Basic code snippets: