Author Topic: Categories  (Read 328 times)

0 Members and 1 Guest are viewing this topic.

Offline HektoRTopic starter

  • Enthusiast
  • Posts: 75
    • View Profile
Categories
« on: November 19, 2008, 11:50:37 AM »
hello all.
i want to know how can i to write php code, wich can add categories.
please help me.

Offline divadiva

  • Enthusiast
  • Posts: 171
    • View Profile
Re: Categories
« Reply #1 on: November 19, 2008, 11:56:02 AM »
What kind of catgeories you want to add?

Offline HektoRTopic starter

  • Enthusiast
  • Posts: 75
    • View Profile
Re: Categories
« Reply #2 on: November 19, 2008, 12:03:42 PM »
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

Offline HektoRTopic starter

  • Enthusiast
  • Posts: 75
    • View Profile
Re: Categories
« Reply #3 on: November 19, 2008, 12:16:41 PM »
no one knows?

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: Categories
« Reply #4 on: November 19, 2008, 12:26:10 PM »
no one knows what you want

Offline premiso

  • Karma Chameleon
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,671
  • Gender: Female
  • effing right
    • View Profile
    • PHP Help
Re: Categories
« Reply #5 on: November 19, 2008, 01:07:14 PM »
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.

Code: [Select]
<?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.

Offline premiso

  • Karma Chameleon
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,671
  • Gender: Female
  • effing right
    • View Profile
    • PHP Help
Re: Categories
« Reply #6 on: November 19, 2008, 01:29:27 PM »
And edit to the above test data:

Code: [Select]
/*
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');
*/