PHP function to delete specific mysql row(s) and update rest othe rows - PLEASE HELP

Discussion in 'PHP' started by KingCobra, Sep 27, 2011.

  1. #1
    I have a mySQL table with some rows. See the image:

    http://imageshack.us/photo/my-images/9/tablesm.gif/
    http://img193.imageshack.us/img193/2531/treej.gif

    I need a PHP function/script that will delete specific row(s) from the table and update rest of the rows.
    I want to delete row(s) based on 'Def' column. Suppose I want to delete row(s) whose Def value is 'L4'

    Then the function will delete 3 rows (because 3 rows have L4 value and update/re-value 'Id, Parent & Def' column for rest of the rows.
    That means: (see 5th row whare there is a value L5)
    L5 will rename to L4, and also rename its Id & Parent column.
    (note there may have more rows like L6, L7 etc)

    Actually this mysql table used for Data Tree.

    Here is some help if you need. You can take a look to write the function, maybe it can help you (not sure):

    Human Language Program – delete tree level

    Variables:
    $TreeID = “G1000”
    $HighestLevel
    $DeleteLevel
    $NewParent

    Steps:
    1. Query tree records [recordset = SQLQuery (Select * from <table> where G=$TreeID sort DESC)]
    2. $HighestLevel = recordset.row(1).DEFvalue
    3. For each record in recordset
    - a. Scroll through the record set and capture $DeleteLevel when DEF changes
    - b. Exit for loop when you determine $DeleteLevel
    4. For each record where DEF=$HighestLevel
    - a. $NewParent = Select Parent where current.record.parent = any_record.id
    - b. Set current.record.parent = $NewParent.value
    - c. Loop until all records are updated
    5. Delete records where DEF=$DeleteLevel
    6. For each record where DEF = $HighestLevel
    - a. Update DEF to = $DeleteLevel
    - b. Loop until all records are updated.
    Your done.
     
    KingCobra, Sep 27, 2011 IP
  2. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    KingCobra, Sep 27, 2011 IP