php 新闻简单建表,查询,下拉分类实例
2015-04-05 01:35
260 查看
(一)创建新闻发布系统,表名为message有如下字段 (3分)
id 文章id
title 文章标题
content 文章内容
category_id 文章分类id
hits 点击量
答:CREATE TABLE 'message'(
'id' int(10) NOT NULL auto_increment,
'title' varchar(200) default NULL,
'content' text,
'category_id' int(10) NOT NULL,
'hits' int(20),
PRIMARY KEY('id');
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
(二)同样上述新闻发布系统:表comment记录用户回复内容,字段如下 (4分)
comment_id 回复id
id 文章id,关联message表中的id
comment_content 回复内容
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0
答:SELECT message.id id,message.title title,IF(message.`hits` IS NULL,0,message.`hits`) hits,
IF(comment.`id` is NULL,0,count(*)) number FROM message LEFT JOIN
comment ON message.id=comment.id GROUP BY message.`id`;
(三)上述内容管理系统,表category保存分类信息,字段如下 (3分)
category_id int(4) not null auto_increment;
categroy_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单
答:function categoryList()
{
$result=mysql_query("select category_id,categroy_name from category")
or die("Invalid query: " . mysql_error());
print("<select name='category' value=''>\n");
while($rowArray=mysql_fetch_array($result))
{
print("<option value='".$rowArray['category_id']."'>".$rowArray['categroy_name']."</option>\n");
}
print("</select>");
}
id 文章id
title 文章标题
content 文章内容
category_id 文章分类id
hits 点击量
答:CREATE TABLE 'message'(
'id' int(10) NOT NULL auto_increment,
'title' varchar(200) default NULL,
'content' text,
'category_id' int(10) NOT NULL,
'hits' int(20),
PRIMARY KEY('id');
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
(二)同样上述新闻发布系统:表comment记录用户回复内容,字段如下 (4分)
comment_id 回复id
id 文章id,关联message表中的id
comment_content 回复内容
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0
答:SELECT message.id id,message.title title,IF(message.`hits` IS NULL,0,message.`hits`) hits,
IF(comment.`id` is NULL,0,count(*)) number FROM message LEFT JOIN
comment ON message.id=comment.id GROUP BY message.`id`;
(三)上述内容管理系统,表category保存分类信息,字段如下 (3分)
category_id int(4) not null auto_increment;
categroy_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单
答:function categoryList()
{
$result=mysql_query("select category_id,categroy_name from category")
or die("Invalid query: " . mysql_error());
print("<select name='category' value=''>\n");
while($rowArray=mysql_fetch_array($result))
{
print("<option value='".$rowArray['category_id']."'>".$rowArray['categroy_name']."</option>\n");
}
print("</select>");
}
相关文章推荐
- php+mysql查询优化简单实例
- php简单实现查询数据库返回json数据(返回json数据函数实例)
- PHP中把数据库查询结果输出为json格式简单实例
- PHP实现简单的新闻发布系统实例
- php+mysql查询优化简单实例
- PHP不使用递归的无限级分类简单实例
- PHP实现简单的新闻发布系统实例
- PHP实例:用PHP简单实现多条件查询
- PHP实例:用PHP简单实现多条件查询
- php生成静态页面的简单实例
- eclipse中简单的数据库查询实例以及Quantum插件简介
- 简单好用的PHP无限分类
- (教学思路 C#之类五)类的分类(静态类、实例类、嵌套类、结构、简单的抽象类、简单的密封类)
- (教学思路 C#之类五)类的分类(静态类、实例类、嵌套类、结构、简单的抽象类、简单的密封类)
- PHP简单系统查询模块代码打包下载
- PHP无限级分类简单实现方法
- php+mysql写的简单留言本实例代码
- php+mysql写的简单留言本实例代码
- Ajax+PHP简单基础入门实例教程
- 实例详细学习PHP的简单语法