Home > php教程 > php手册 > php实现只保留mysql中最新1000条记录

php实现只保留mysql中最新1000条记录

WBOY
Release: 2016-06-06 20:03:11
Original
782 people have browsed it

这篇文章主要介绍了php实现只保留mysql中最新1000条记录的方法和相关示例及数据库结构,十分的全面,有需要的小伙伴可以参考下。

$limit){ $query="select `id` from `news` order by `id` desc limit ".$limit; $result=mysql_query($query); mysql_data_seek($result,$limit-1); $data=mysql_fetch_array($result); $query="delete from `news` where `id`

test.sql

-- phpMyAdmin SQL Dump
-- version 3.1.5-rc1
--
--
-- 主机: localhost
-- 生成日期: 2010 年 08 月 19 日 05:47
-- 服务器版本: 5.0.18
-- PHP 版本: 5.2.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- 数据库: `test`
--

-- --------------------------------------------------------

--
-- 表的结构 `news`
--

CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) unsigned NOT NULL auto_increment, `title` varchar(256) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gb2312;

以上所述就是本文的全部内容了,希望大家能够喜欢。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template