Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Adjacency List model recursive deletion

  1. #11
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default trial and error in progress

    Now... its 12.15 (IST). i am implementing that code...
    first i did not look into it properly and upon your reply i felt ah... thats the code... the recursion.
    ok let me complete and post the status. so that people will benefit.
    meanwhile... can we have this thread title as adjacency list model recursive deletion or an appropriate one so that it will be really useful for searchers.

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The thread title has been changed-- the old title still exists only as a redirect, and that will only remain for a few days.

    Hope it works... post back if you have problems.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default the mystic result

    Hi,
    i would like to show you this mystic result

    PHP Code:
        function delete()
        {
            
    $id $this->input->post('id');
            
    $this->deletecategory($id);
        }
        
        function 
    deletecategory($cat_id)
        {
            
    $query "SELECT id,cop from products WHERE pid='$cat_id'";
            echo 
    $query."\n";
            
    $q mysql_query($query);
            while(
    $row mysql_fetch_assoc($q))
            {
                if(
    $row['cop'])//if category
                
    {
                    
    $this->deletecategory($row['id']); //loop to the lower level
                
    }
            }
            
    $qy "DELETE FROM products WHERE id='".$row['id']."';";
            echo 
    $qy."\n";
    //        $q = mysql_query($qy); //remove this entry
        

    i am getting this as result...

    Code:
    SELECT id,cop from products WHERE pid='8'
    SELECT id,cop from products WHERE pid='9'
    DELETE FROM products WHERE id='';
    SELECT id,cop from products WHERE pid='10'
    DELETE FROM products WHERE id='';
    DELETE FROM products WHERE id='';
    the variable row[id'] is going out out scope after this line
    $this->deletecategory($row['id']); //loop to the lower level

    Why?

    I have used recursion for files and folders and it works well but i did not
    use that to this process. what am i missing here?
    Last edited by jayapalchandran; 07-15-2010 at 12:05 PM.

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This line:
    $qy = "DELETE FROM products WHERE id='".$row['id']."';";

    Should be within the "while" loop, after the if, or maybe within an "else".

    The order I had before was correct (I think), so if you need more help start by comparing what I posted and this new code you wrote. I think it's close, but the order isn't quite correct.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    jayapalchandran (07-28-2010)

  6. #15
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Voila. It is working like you said.

    Yes. after moving that line into the loop it worked.
    I have been in other project and now back to this work so it is just now i was working with this to update like the below and it worked.
    Thank you.

    PHP Code:
    function delete() 
        { 
            
    $id $this->input->post('id'); 
            
    $this->deletecategory($id);
            
    $this->db->query("delete from products where id=$id"); 
        } 
         
        function 
    deletecategory($cat_id
        { 
            
    $query "SELECT id,cop from products WHERE pid='$cat_id'"
            echo 
    $query."\n"
            
    $q mysql_query($query); 
            while(
    $row mysql_fetch_assoc($q)) 
            { 
            
    $id $row['id'];
                if(
    $row['cop'])//if category 
                

                    
    $this->deletecategory($row['id']); //loop to the lower level 
                

            
    $qy "DELETE FROM products WHERE id='".$row['id']."';"
            
    //echo $qy."\n"; 
            
    $q mysql_query($qy); //remove this entry 

            

        } 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •