我对php和mysql的了解有限,我正在尝试学习它,同时从头开始创建一个非常简单的CMS,以结合我的PHPBB论坛 .
CMS功能齐全,但我只能创建1个级别的类别 . 我没有多级别的类别,任何帮助将不胜感激 .
我在类别中有以下列 - cID, Headers ,描述,级别,依赖 . 根据需要包括父类别的cID值,Level应该是父类别的级别值的1 .
这是我到目前为止没有运气 - 功能:
function addCat($cName, $cDesc, $property) {
$property = "$cLevel, $cDepend";
$query = mysql_query("INSERT INTO categories VALUES(null,'$cName','$cDesc', '$cLevel', '$cDepend')") or die(mysql_error());
}
类别选择器的html:
<form action="doAddC.php" method="post">
<td><label for="">Category</label></td>
<td><select name="'CatLevel''CatDepend'">
<?php
$result = mysql_query("SELECT * FROM categories");
while($cat = mysql_fetch_assoc($result)){
?>
<option value="'CatLevel':'<?php echo $cat['Level']; ?>','CatDepend':'<?php echo $cat['cID']; ?>'"><?php echo $cat['Title']; ?></option>
<?php
}
?>
</select></td>
doAddC.php
if(isset($_POST['submit'])) {
if(isset($_POST['CatName'])) {
if(isset($_POST['CatDesc'])) {
addCat($_POST['CatName'], $_POST['CatDesc'], $_POST['CatLevel']['CatDepend']);
header("Location: cats.php");
} else {
echo "Please Add the Category Description!";
include('addCat.php');
}
} else {
echo "Please Set the Category Name!";
include('addCat.php');
}
} else {
header("Location: addCat.php");
}
在最佳方案中,Level和Reduction在数据库中等于0 . 我甚至不知道在手册中找到这个 .
1 回答
问题已经解决了 . 那些可能正在努力解决类似问题的人的代码如下 .
HTML快照:
doAddC.php的快照:
功能快照:
任务完成 :)