php编写简单的文章发布程序
本文给大家分享的是使用php编写简单的文章发布程序,适合php菜鸟学习参考,希望对大家学习php能够有所帮助。
--
-- 表的结构 `yi_article`
--
CREATE TABLE IF NOT EXISTS `yi_article` ( `id` int(11) unsigned NOT NULL auto_increment, `title` varchar(256) NOT NULL, `content` mediumtext NOT NULL, `add_man` varchar(20) NOT NULL, `add_time` datetime NOT NULL, `views` int(11) NOT NULL, `tag` tinyint(4) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ;
article.php
load->library('myclass');
$this->load->database();
$this->load->helper('url');
$this->tips=array(
'required'=>' [%s] 是必须填写的!',
'is_unique'=>'此 [%s] 已经存在,,请输入其它名称!',
'min_lenght'=>' [%s] 最小长度为 [%s]',
'max_length'=>'[%s] 最大长度为 [%s]'
);
}
function index(){
echo "这里是文章的首页";
echo "
";
//加载url辅助函数
$this->load->helper('url');
$addr=site_url('article/article_list');
echo "查看文章";
$addr=site_url('article/article_page');
echo "查看分页";
}
function article_list(){
echo "这里是文章列表";
//加载数据库模型
//$this->load->model('article_model');
//$this->article_model->index();
//读取所有的文章
$this->load->database();
echo "
";
$query=$this->db->where("id >",5)->select('id,title')->from('article')->order_by('id','desc')->limit(4)->get();
$info=$query->result_array();//当然你可以用result()
$this->myclass->p($info);
echo "第一条记录的标题:".$info[0]['title'];
echo "
";
echo "第二条记录的标题:".$info[1]['id'];
echo "
";
echo "表article中共有这么些记录:".$this->db->count_all('article');
echo "
";
echo "本次共查询出这么些条记录:".$query->num_rows();
}
function article_page($page=1){
///////////////////////////////////
$config=array();
//第一步查询出总记录数
$this->load->database();
$config['total_rows']=$this->db->select('*')->from('article')->count_all_results();
//每页记录数
$config['per_page']=5;
//基础url
$this->load->helper('url');
$config['base_url']=site_url('article/article_page');
//显示的链接数
$config['num_links']=100;
//在地址栏显示当前页码
$config['use_page_numbers']=true;
//定义首页
$config['first_link']='首页';
//定义末页
$config['last_link']='尾页';
//上一页
$config['prev_link']='上一页';
//下一页
$config['next_link']='下一页';
//把分页包起来
$config['full_tag_open']='
'; $config['full_tag_close']='
'; //第二步加载类库 $this->load->library('pagination'); $this->pagination->initialize($config); echo $this->pagination->create_links(); ///////////////////////////////////// $page=$page?intval($page):1; $start=($page-1)*$config['per_page']; $query=$this->db->select('*')->from('article')->limit($config['per_page'],$start); $info=$query->get()->result_array(); $this->myclass->p($info); echo $this->pagination->create_links(); //echo base_url('abc/def'); } protected function _page($total_rows,$per_page,$base_url){ /////////////////////////////////// $config=array(); //第一步查询出总记录数 //$this->load->database();//// $config['total_rows']=$total_rows; //每页记录数 $config['per_page']=$per_page; //基础url $this->load->helper('url');//// $config['base_url']=site_url($base_url); //显示的链接数 $config['num_links']=100; //在地址栏显示当前页码 $config['use_page_numbers']=true; //定义首页 $config['first_link']='首页'; //定义末页 $config['last_link']='尾页'; //上一页 $config['prev_link']='上一页'; //下一页 $config['next_link']='下一页'; //把分页包起来 $config['full_tag_open']=''; $config['full_tag_close']='
'; //第二步加载类库 $this->load->library('pagination'); $this->pagination->initialize($config); return $this->pagination->create_links(); ///////////////////////////////////// } function page($page=1){ $config['per_page']=5; $page=$page?intval($page):1; $start=($page-1)*$config['per_page']; $query=$this->db->select('*')->from('article')->limit($config['per_page'],$start); $info=$query->get()->result_array(); return $info; } function article_add(){ $this->load->library('form_validation'); //开始设置验证规则 //set_message可以传一个一维数组 $chinesetips=$this->tips; $this->form_validation->set_message($chinesetips); /* $this->form_validation->set_message('required', ' [%s] 是必须填写的!'); $this->form_validation->set_message('is_unique', '此 [%s] 已经存在,请输入其它名称!'); $this->form_validation->set_message('min_length', ' [%s] 最小长度为 [%s]'); $this->form_validation->set_message('max_length', ' [%s] 最大长度为 [%s]'); */ $this->form_validation->set_rules('title','标题','trim|required|is_unique[article.title]|min_length[6]|max_length[12]'); $this->form_validation->set_rules('content','内容','required'); $this->form_validation->set_rules('tag','状态','required'); if($this->form_validation->run()==true){ echo "表单验证成功!"; print_r($this->input->post()); $data=$this->input->post(); unset($data['Submit']); $data['add_time']=date('Y-m-d H:i:s'); $data['views']='0'; $st=$this->db->insert('article',$data); if($st){ echo "数据插入成功!"; echo "新的id为:".$this->db->insert_id(); } //echo get_magic_quotes_gpc(); }else{ echo "表单验证失败!"; echo ""; echo validation_errors(); } } function article_add_viewer(){ $this->load->helper('url'); $this->load->view('article_add'); } function article_links(){ $addr=site_url('article/article_mod_viewer/19'); echo "修改19"; } function article_mod_viewer($id){ if($id==""){ echo "没有传递参数"; exit; } $this->load->helper('url'); //从数据库中查出来 $query=$this->db->select()->from('article')->where('id',$id)->get(); $info=$query->row_array(); print_r($info); $this->load->view('article_mod',$info); } function abc($val){ $this->form_validation->set_message('abc','不行'); //p($val); return true; } function article_mod(){ $this->load->library('form_validation'); //开始设置验证规则 //set_message可以传一个一维数组 $chinesetips=$this->tips; $this->form_validation->set_message($chinesetips); $this->form_validation->set_rules('title','标题','trim|required|min_length[6]|max_length[12]|callback_abc'); $this->form_validation->set_rules('content','内容','required'); $this->form_validation->set_rules('tag','状态','required'); if($this->form_validation->run()==true){ echo "表单验证成功!"; print_r($this->input->post()); $data=$this->input->post(); $id=$data['id']; unset($data['id']); unset($data['Submit']); $data['add_time']=date('Y-m-d H:i:s'); $data['views']='0'; //p($data); $st=$this->db->where('id',$id)->update('article',$data); if($st){ echo "数据修改成功"; }else{ echo "数据修改失败"; } }else{ echo "表单验证失败!"; echo "
"; echo validation_errors(); } } function article_del($id=''){ if($id==""){ //exit('请传id'); } $id=array(17,18,19); $this->db->where_in('id',$id)->delete('article'); $st=$this->db->affected_rows(); echo $st; if($st){ echo "数据删除成功!"; }else{ echo "数据删除失败!"; } } } ?>
article_add.php

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.
