Jump to content

help getting child category into a db


tryingtolearn

Recommended Posts

I have the following result that I am getting from a source.

 

SimpleXMLElement Object
(
    [CategoryID] => 1
    [Name] => Other
    [Order] => 0
    [link] => http://www.link.com?sub=1
)

SimpleXMLElement Object
(
    [CategoryID] => 1233916011
    [Name] => ceramic 
    [Order] => 1
    [ChildCategory] => SimpleXMLElement Object
        (
            [CategoryID] => 1234016011
            [Name] => dish
            [Order] => 1
        )

    [link] => http://www.link.com?sub=13476
)

SimpleXMLElement Object
(
    [CategoryID] => 1233917011
    [Name] => laminate
    [Order] => 2
    [link] => http://www.link.com?sub=98247
)

I need to get it into a database with the following structure

 

id  categoryID  cName  cOrder  clink  cparent

 

 

By using

foreach($this->resp->Store->CustomCategories->CustomCategory as $cat) {
	$sub = $cat->CategoryID;
	$ord = $cat->Order;
	$linkto = "$stlink?fsub=$fsub";
	$nm = htmlspecialchars($cat->Name);
	$par=$cat->ChildCategory->Order;
	$query = "INSERT INTO Cat (categoryID,cName,cOrder,clink,cparent) VALUES ('$sub','$nm','$ord','$linkto','$par')";		
	$result = @mysql_query ($query); // Run the query.
	}

 

I can get

id   categoryID   cName   cOrder  clink                          cparent
1    1            Other   0       http://www.link.com?sub=1      0
2    1233916011   ceramic 1       http://www.link.com?sub=13476  0
2    1233917011   laminate 2      http://www.link.com?sub=98247  0

 

But I need to get the ChildCategory in there w/ cparent like

id   categoryID   cName   cOrder  clink                          cparent
1    1            Other   0       http://www.link.com?sub=1      0
2    1233916011   ceramic 1       http://www.link.com?sub=13476  0
3    1234016011   dish    1                                      1  <--- like this
4    1233917011   laminate 2      http://www.link.com?sub=98247  0

 

any help appreciated...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.