数据库设计题:
该题只需设计ER图,ER图如下:
readerreader_no:表示借阅证号码max_book:表示该借阅证最多借几本书I:表示整型reader_idNOreader_noA11max_bookIreader_id
选择题:
1.B,D(说明:用户输入未经过滤就直接送往了数据库,这非常危险。如果URL包含ID=0+OR+1这样的参数时,实际的查询为DELETE FROM MYTABLE WHERE ID = 0 OR 1,数据库将删除表中所有的记录。) 2.A
3.C
4.A(说明:mysql_fetch_field函数从结果集中取得列信息并作为对象返回) 5.C
填空题:
过滤特殊字符。 addslashes 问答题: 1.答案参见9.1.6
2.
在index.php文件中写入如下代码:
function GenerateMenu($id=0,$str=\
$result=mysql_query(\ while($row=mysql_fetch_array($result)){ }
echo $str.$row[\
GenerateMenu($row[\
mysql_free_result($result);
}
$link=mysql_connect(\mysql_select_db(\GenerateMenu(); mysql_close($link); ?>
3.
数据库的这个分类表可以设计大概如下,类举例如下: categoryID categoryName categoryParentID 1 电脑数码 0 2 3 4
娱乐休闲 电脑常识 电影电视
0 1 2
5 主机 3
categoryParentID为0表示为第一级分类,categoryParentID为1表示为id =1的子分类,也就是说电脑常识是电脑数码的子目录,其它也类似。。。
数据表结构如下:
CREATE TABLE `category` (
`categoryID` smallint(5) unsigned NOT NULL auto_increment, `categoryParentID` smallint(5) unsigned NOT NULL default '0', `categoryName` varchar(50) NOT NULL default '', PRIMARY KEY (`categoryID`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
INSERT INTO `category` ( `categoryParentID`, `categoryName`) VALUES (0, '一级类别'), (1, '二级类别'), (1, '二级类别'),
(1, '二级类别'), (2, '三级类别'), (2, '333332'), (2, '234234'), (3, 'aqqqqqd'), (4, '哈哈'), (5, '66333666');
*/
//指定分类id变量$category_id,然后返回该分类的所有子类 //$default_category为默认的选中的分类
function Get_Category($category_id = 0,$level = 0, $default_category = 0){ global $DB; $sql = \ categoryID DESC\
$result = $DB->query( $sql );
=>
while ($rows = $DB->fetch_array($result)){ $category_array[$rows[categoryParentID]][$rows[categoryID]] = array('id' $rows[categoryID], 'parent' => $rows[categoryParentID], 'name' => $rows[categoryName]); }
if (!isset($category_array[$category_id])){
return \
}
foreach($category_array[$category_id] AS $key => $category){
if ($category['id'] == $default_category){
echo \}else{
echo \}if ($level > 0){
echo \}else{
echo \ }
Get_Category($key, $level + 1, $default_category); }
unset($category_array[$category_id]);
}
function Category_array($category_id = 0,$level=0){ global $DB; $sql = \ categoryID DESC\
$result = $DB->query($sql);
while ($rows = $DB->fetch_array($result)){
$category_array[$rows['categoryParentID']][$rows['categoryID']] = $rows; }
foreach($category_array AS $key=>$val){
if ($key == $category_id){ foreach ($val AS $k=> $v){
$options[$k] = array('id' => $v['categoryID'], 'name' => $v['categoryName'],
'level' => $level, 'ParentID'=>$v['categoryParentID']); }
}
unset($category_array[$category_id]); return $options;
}
}
$children = Category_array($k, $level+1); if (count($children) > 0){ }
$options = $options + $children;
class cate{
}
function getFlush($category_id = 0,$level = 0, $default_category = 0){ ob_start(); function Get_Category($category_id = 0,$level = 0, $default_category = 0){ echo $category_id; $arr = array( '0' => array(
'1' => array('id' => 1, 'parent' => 0, 'name' => '1111'), '2' => array('id' => 2, 'parent' => 0, 'name' => '2222'), '4' => array('id' => 4, 'parent' => 0, 'name' => '4444') ),
'1' => array(
'3' => array('id' => 3, 'parent' => 1, 'name' => '333333'), '5' => array('id' => 5, 'parent' => 1, 'name' => '555555') ),
'3' => array(
'6' => array('id' => 6, 'parent' => 3, 'name' => '66666'), '7' => array('id' => 7, 'parent' => 3, 'name' => '77777') ),
'4' => array(
'8' => array('id' => 8, 'parent' => 4, 'name' => '8888'), '9' => array('id' => 9, 'parent' => 4, 'name' => '9999') )
);
if (!isset($arr[$category_id])){ return \}
foreach($arr[$category_id] AS $key => $cate){ if ($cate['id'] == $default_category){
$txt = \}else{ $txt = \
}
if ($level > 0){
$txt1 = \}else{ }
$txt1 = \
$val = $txt.$txt1;
echo $val;
self::Get_Category($key, $level + 1, $default_category); }
}
}
self::Get_Category($category_id ,$level, $default_category); $out = ob_get_contents(); ob_end_clean(); return $out;
$id =$_GET['id']; echo \ $c = new cate(); //$c->Get_Category(); $ttt=$c->getFlush($id,'0','3'); echo $ttt;
echo \ ?>
然后在浏览器地址栏中输入:http://localhost/index.php?id=1
第10章答案:
任务1答案: create table message (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, title varchar(100), content varchar(225), category_id int, hits int )
任务2答案:
select a.id, a.title, a.hits, if(ifnull(b.id,false),count(*),0) as replay from message a left join comment b on a.id=b.id group by a.id order by replay desc 任务3答案: function categoryList() {
$result=mysql_query(\ or die(\ print(\ while($rowArray=mysql_fetch_array($result)) {
print(\
value='\ }
print(\}