我有一个JSON文件,可以将数据输入iOS。我还想看看是否有超过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);
}
}
?>
答案 0 :(得分:0)
您正在使用LIMIT 1,这意味着您只能获得1条记录。你打算增加限额吗?
如果你需要剔除返回的记录数组,你总是可以使用PHP count()函数和array_slice()函数...