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
https://forums.phpfreaks.com/topic/257154-array-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.