【发布时间】:2013-12-20 20:32:56
【问题描述】:
我有一个将数据带入 iOS 的 JSON 文件。我也想让它看看是否有超过 2 条记录。
如果有超过 2 条记录,我希望它删除除最后 2 条记录之外的所有内容
如何将它插入到这个 php 文件中
$connection = mysql_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}
else
{
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}
else
{
$query = "SELECT * FROM test ORDER BY id DESC LIMIT 1";
$resultset = mysql_query($query, $connection);
$records = array();
//Loop through all our records and add them to our array
while($r = mysql_fetch_assoc($resultset))
{
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
}
}
?>
【问题讨论】: