I will not develop the whole system. But since I needed a script to do categories for myself here is a basic usage script. This will get categories in a table in an array in the order specified.
<?php
/*
* My attempt at a category script.
*/
/*
create table categories (
catid INT(11) NOT NULL auto_increment,
parentid INT(11) NOT NULL default '0',
catname varchar(50) NOT NULL,
catseoname varchar(50) NOT NULL,
disporder INT(3) NOT NULL default '0',
primary key(catid)
);
*/
mysql_connect("localhost", "root", "");
mysql_select_db("cat");
/*
my test data
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('0', 'Test1', 'test1', '0');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('1', 'Test1-1', 'test1-1', '0');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('1', 'Test1-2', 'test1-2', '1');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('5', 'Test2-1', 'test2-1', '0');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('0', 'Test2', 'test2', '1');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('5', 'Test2-2', 'test2-2', '1');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('7', 'Test2-2-2', 'test2-2-2', '1');
insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('7', 'Test2-2-1', 'test2-2-1', '0');
*/
function retrieveCategoryList() {
$query = mysql_query("SELECT catid, parentid, catname, catseoname, disporder FROM categories WHERE parentid = 0 ORDER BY disporder, catname");
while ($row = mysql_fetch_assoc($query)) {
$catArray[$row['catname']]['id'] = $row['catid'];
$catArray[$row['catname']]['parentid'] = $row['parentid'];
$catArray[$row['catname']]['catseoname'] = $row['catseoname'];
$catArray[$row['catname']]['disporder'] = $row['disporder'];
$catArray[$row['catname']]['subcats'] = fetchSubCat($row['catid']);
}
return $catArray;
}
// recursive
function fetchSubCat($parentid) {
$query = mysql_query("SELECT catid, parentid, catname, catseoname, disporder FROM categories WHERE parentid = " . $parentid . " ORDER BY disporder, catname");
$numRows = mysql_num_rows($query);
$catArray = "none";
if ($numRows > 0) {
$catArray=array();
while ($row = mysql_fetch_assoc($query)) {
$catArray[$row['catname']]['id'] = $row['catid'];
$catArray[$row['catname']]['parentid'] = $row['parentid'];
$catArray[$row['catname']]['catseoname'] = $row['catseoname'];
$catArray[$row['catname']]['disporder'] = $row['disporder'];
$catArray[$row['catname']]['subcats'] = fetchSubCat($row['catid']);
}
}
return $catArray;
}
?>
You will need to figure out how to use this to add more categories/edit/ get a category etc. Like I said it is very basic but hopefully it will help you on your way.