Creating categories in table
Posted: Mon Nov 27, 2006 6:29 am
feyd | Please use
result:
Here is the table structure for the categories in the database:
anyone can tell me where to go from here. I need to get the $category_array parsed into the table.
Basically I need to get all the values in the array into the category_name field wth its own unique category_id...
Then I need to get the first level of the array as the parent_category_id and the rest of the array dimensions as the child categories. which is represented in the table in category_path like so
I hope this makes sense to somebody that can help me.... I am really in a bind trying to build this import application...
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have alot of products I have to import into my shopping cart. Problem is I need to create my category structure on the fly. I have learned php on my own and this is just a little beyond my knowledge. Hopefully someone can help me.
Basically the I have a .csv file of products I am importing into a table. One field contains the category structure in this format:
parent_category|child1|child2|child3 etc...
I am using the following code to pull that data into an array....Code: Select all
while($data = mysql_fetch_array($result)){
$categories = $data['CATEGORIES'];
$category_array = explode("|", $categories);Code: Select all
Array
(
[0] => Consumer Electronics
[1] => TV and Video
[2] => TVs
[3] => 30 & Over
)
Array
(
[0] => Home and Garden
[1] => Furniture
[2] => Other
)
Array
(
[0] => Home and Garden
[1] => Furniture
[2] => Other
)Code: Select all
CREATE TABLE `va_categories` (
`category_id` int(11) NOT NULL auto_increment,
`parent_category_id` int(11) NOT NULL default '0',
`category_path` varchar(255) NOT NULL default '',
`category_name` varchar(255) NOT NULL default '',
`category_order` int(11) NOT NULL default '1',
`is_showing` int(11) default '0',
`short_description` text,
`full_description` text,
`image` varchar(255) default NULL,
PRIMARY KEY (`category_id`,`category_name`),
KEY `category_path` (`category_path`),
KEY `parent_category_id` (`parent_category_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;Basically I need to get all the values in the array into the category_name field wth its own unique category_id...
Then I need to get the first level of the array as the parent_category_id and the rest of the array dimensions as the child categories. which is represented in the table in category_path like so
Code: Select all
parent_category = 0
child1 = 1
child2 = 2
child3 = 3
0,1
0,2
0,1,3
etc....feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]