Jump to content

Array problem


drisate

Recommended Posts

Hey guys i have a table of pages set up with the possability of inserting pages inside pages. I am trying to make a delete button that would delete every child pages creating an array of page id's.

 

page 1

L page 1.1

L page 1.2

L page 1.3

L page 1.4

page 2

 

my code looks like this so fare

 

class delete_page
{

    function page($cat_id, $x = ''){
        
        $sql = mysql_query("SELECT * FROM pages WHERE parent='$cat_id' order by id asc");
        while ($select = mysql_fetch_assoc($sql)) {
            
            $this->x[] = $select['id'];
            $this->x = $this->page($select['id'], $this->x);
        }
        
        return $this->x;
        
    }

    function get_page($cat_id){
        return $this->page($cat_tid);
    }

}

$page = new delete_page;
$get_array_page = $page->get_page(1);

 

For some reason the above code sends me an array of all the pages in the database instead of returning only the child pages of the ID i inserted in the $get_array_page = $page->get_page(1)

 

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)

 

It should normaly return only

 

page 1

L page 1.1

L page 1.2

L page 1.3

L page 1.4

 

with out

page 2

 

like this

 

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

 

What did i miss?

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.