一、PHP/MySQL編程 1) 某內容管理系統中,表message有如下欄位 id 文章id title 文章標題 content 文章內容 category_id 文章分類id hits 點擊量 建立上表,寫出MySQL語句 2)同樣上述內容管理系統:表comment記錄使用者回複內容,欄位如下 comment_id 回複id id 文章id,關聯message表中的id comment_content 回複內容 現通過查詢資料庫需要得到以下格式的文章標題列表,並按照回複數量排序,回複最高的排在最前面 文章id 文章標題 點擊量 回複數量 用一個SQL陳述式完成上述查詢,如果文章沒有回複則回複數量顯示為0 3) 上述內容管理系統,表category儲存分類資訊,欄位如下 category_id int(4) not null auto_increment; categroy_name varchar(40) not null; 使用者輸入文章時,通過選擇下拉式功能表選定文章分類 寫出如何?這個下拉式功能表 drop table if exists Comment;drop table if exists category; drop table if exists message; /**//*==============================================================*/ /**//* Table: Comment */ /**//*==============================================================*/ create table Comment ( comment_id int unsigned not null, id int unsigned not null, comment_content text, primary key (comment_id) ) type = InnoDB; /**//*==============================================================*/ /**//* Table: category */ /**//*==============================================================*/ create table category ( category_id int not null AUTO_INCREMENT, category_name varchar(40) not null, primary key (category_id), key AK_pk_category_id (category_id) ) type = InnoDB; /**//*==============================================================*/ /**//* Table: message */ /**//*==============================================================*/ create table message ( id int not null, title varchar(120) not null, content text not null, category_id int unsigned, hit int unsigned, primary key (id) ) type = InnoDB; select A.id,A.title,A.hits,IFNULL(B.num,0) from message A left join (select id,count(*) as num from comment B group by id) B on A.id=B.id order by B.num desc; <html> <head><title>JS列印</title></head> <body> <form> <select id="category" name="category"> <?php mysql_connect("localhost","root","") or die("db conn error:".mysql_error()); mysql_select_db("phpinterview") or die("db error".mysql_error()); $result=mysql_query("select category_id,category_name from category"); while($row=mysql_fetch_array($result)) { echo "<option value='".$row["cateogry_id"]."'>".$row["category_name"]."</option>"; } ?> </select> </form> </body>
|