php连接mysql count与下拉基本用法

来源:互联网 发布:编程过滤器的工作原理 编辑:程序博客网 时间:2024/06/05 02:19


以下请用PHPMYADMIN完成


(一)创建新闻发布系统,表名为message有如下字段 (3分)


id 文章id
title 文章标题
content 文章内容
category_id 文章分类id
hits 点击量


(二)同样上述新闻发布系统:表comment记录用户回复内容,字段如下 (4分)


comment_id 回复id
id 文章id,关联message表中的id
comment_content 回复内容
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0


SELECT t. * , (


SELECT count( * ) 
FROM COMMENT tt
WHERE tt.id = t.id
)num
FROM `message` t order by num desc
LIMIT 0 , 30 ;


(三)上述内容管理系统,表category保存分类信息,字段如下


category_id int(4) not null auto_increment;
categroy_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单


Function selectCategory($arr)
{
If( empty($arr) ){
Return “<select name=’category’><option>暂无分类</option></select>”;
}
$str = “<select name=’category’><option>文章分类</option>”;
Foreach($arr as $v){
$str.=“<option value=’”.$v[‘category_id’].”’>”.$v[‘category_name’].”</option>”;
}
$str .= “</select>”;
Return $str;


}
0 0
原创粉丝点击