HektoR Posted November 19, 2008 Share Posted November 19, 2008 hello all. i want to know how can i to write php code, wich can add categories. please help me. Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/ Share on other sites More sharing options...
divadiva Posted November 19, 2008 Share Posted November 19, 2008 What kind of catgeories you want to add? Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693609 Share on other sites More sharing options...
HektoR Posted November 19, 2008 Author Share Posted November 19, 2008 something like this http://site.com/cat.php?cat_id=16 http://site.com/cat.php?cat_id=165 http://site.com/cat.php?cat_id=121 i want to add categories like this from adminstration panel Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693616 Share on other sites More sharing options...
HektoR Posted November 19, 2008 Author Share Posted November 19, 2008 no one knows? Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693631 Share on other sites More sharing options...
sasa Posted November 19, 2008 Share Posted November 19, 2008 no one knows what you want Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693645 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693684 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 And edit to the above test data: /* 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 ('6', 'Test2-2-2', 'test2-2-2', '1'); insert into categories (`parentid`, `catname`, `catseoname`, `disporder`) VALUES ('6', 'Test2-2-1', 'test2-2-1', '0'); */ Quote Link to comment https://forums.phpfreaks.com/topic/133361-categories/#findComment-693707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.