sp数据库增删改时间不断变化,不明白

#1 homexigua

sql:
-- phpMyAdmin SQL Dump
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 01 月 24 日 16:25
-- 服务器版本: 5.1.41
-- PHP 版本: 5.3.1

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 */;

--
-- 数据库: `db`
--

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

--
-- 表的结构 `p_arcticle`
--

CREATE TABLE IF NOT EXISTS `p_arcticle` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(160) NOT NULL,
  `content` text NOT NULL,
  `pubdate` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

--
-- 转存表中的数据 `p_arcticle`
--

INSERT INTO `p_arcticle` (`id`, `title`, `content`, `pubdate`) VALUES
(1, '第1篇文章标题', '第1篇文章内容', 1264319746),
(2, '第2篇文章标题', '第2篇文章内容', 1264319746),
(3, '第3篇文章标题', '第3篇文章内容', 1264319746),
(4, '第4篇文章标题', '第4篇文章内容', 1264319746),
(5, '第5篇文章标题', '第5篇文章内容', 1264319746),
(6, '第6篇文章标题', '第6篇文章内容', 1264320789),
(7, '第7篇文章标题', '第7篇文章内容', 1264321504);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
这是控制器

class main extends spController
{
    //首页显示
    function index(){
        $db = spClass('arcticle');
        $this->list = $db->spPager($this->spArgs('page',1),5)->findAll();
        $this->pager = $db->spPager()->getPager();
    }
    //插入操作
    function insert(){
        $db = spClass('arcticle');
        $arr = array(
            'title' => $this->spArgs('title'),
            'content' => $this->spArgs('content'),
            'pubdate' => time(),
        );
        if($db->create($arr) !== false){
            $this->success('数据添加成功', spUrl("main","index"));
        }else{
             $this->error('数据添加失败', spUrl('main','index'));
        }
    }
    //查看操作
    function view(){
        $db = spClass('arcticle');
        $id = $this->spArgs('id');
        $this->result = $db->find(array('id' => $id));
    }
    //编辑操作
    function edit(){
        $db = spClass('arcticle');
        $id = $this->spArgs('id');
        if($db->find(array('id' => $id))){
            $this->result = $db->find(array('id' => $id));
        }else{
            $this->error('没有查找到数据', spUrl('main','index'));
        }

    }
    //更新操作
    function updata(){
        $db = spClass('arcticle');
        $conditions = array('id' => $this->spArgs('id'));
        $arr = array(
            'title' => $this->spArgs('title'),
            'content' => $this->spArgs('content'),
        );
        if($db->update($conditions, $arr)){
            $this->success('数据更新成功', spUrl('main','index'));
        }else{
            $this->error('数据更新失败', spUrl('main','index'));
        }
    }
    //删除操作
    function delete(){
        $db = spClass('arcticle');
        $id = $this->spArgs('id');
        if($db->deleteByPk($id)){
            $this->success('数据删除成功', spUrl('main','index'));
        }else{
            $this->error('数据删除失败', spUrl('main','index'));
        }      
    }
}
?>

2010-01-25 12:25:30

#2 homexigua





首页



  

您的标题:

  

留言内容:

  

  


  
{foreach from=$list item=vo}
      

  •           {$vo.pubdate|date_format:'%Y-%m-%d %H:%M:%S'}
              {$vo.title}
              |编辑
              |删除
          

  • {/foreach}


    {if $pager}
    共有记录{$pager.total_count}条,共有{$pager.total_page}页(每页{$pager.page_size}条记录):

        {if $pager.current_page != $pager.first_page}
        前页 |
        上一页 |
        {/if}

        {foreach from=$pager.all_pages item=thepage}
            {if $thepage != $pager.current_page}
            {$thepage}
            {else}
            {$thepage}
            {/if}
        {/foreach}

        {if $pager.current_page != $pager.last_page}
        | 下一页
        | 后页
        {/if}
    {/if}


    2010-01-25 12:26:11

    #3 homexigua

    现在问题是首页添加新文章以后,首页那个显示时间的地方每次刷新它都会变化,好像自动更新数据库似的。不清楚怎么回事。

    2010-01-25 12:28:53

    #4 homexigua

    好像添加的文章时间不会变化,但是更新的时间是不断变化的。

    2010-01-25 12:32:07

    #5 jake

    楼主代码写的真漂亮:$

    刚刚就楼主提供的代码做了一次,没有发现问题。提交正常,没有发现有时间更新的情况。

    这里提供我的代码,楼主可以对比一下,检查检查问题在那里。

    netest.rar

    2010-01-25 12:58:41

    #6 homexigua

    知道了,是编辑的时候不清楚为什么直接把数据库里字段值清空了
         //更新操作
         function updata(){
             $db = spClass('arcticle');
             $conditions = array('id' => $this->spArgs('id'));
             $arr = array(
                 'title' => $this->spArgs('title'),
                 'content' => $this->spArgs('content'),
             );
             if($db->update($conditions, $arr)){
                 $this->success('数据更新成功', spUrl('main','index'));
             }else{
                 $this->error('数据更新失败', spUrl('main','index'));
             }
         }
    就是这里,加个 'pubdate' => time(),才行,不明白

    2010-01-27 12:41:35