SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    table rewrite problem

    hi!
    i have a category table which provide links t subcategories....
    so any subcategory have a sub id linked to the id of category...
    so i have ie 4 subcategories linked to category number 3...
    now when i delete this category number 3 i delete the subcategories which is linked to to 3....
    now i want that all subcategories that is linked to categories over number 3 (ie 4, 5, 6) to go a number down like 3, 4, 5...
    i hope im clear!
    any suggestion appreciated!!!
    thanx in advance!

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Perhaps you can use a query like the one below?

    Code:
    UPDATE table SET category = category-1 WHERE category > 3
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok..
    and if i delete category 3 and category 7 of 10 in the same time with foreach...
    suggestions ?
    thanx in advance!

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Then it's a bit more complicated. I think that the easiest way to solve it is to delete the rows backwards (starting with the 7th category), and update the table after each deletion.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i thought something like this.....
    but i looked for a simplier alchemy
    any suggestion about how to invert the loop?
    thanx in avdance..

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If I can come up with a better solution, I'll let you know.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx erik

  8. #8
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by reminder
    any suggestion about how to invert the loop?
    Sorry, I missed that question... Take a look at array_reverse.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i made something like this...
    the post variable is the selection from checkbox array for delete entry...
    PHP Code:
    $arr $_POST["delmenu2"];
    $arr array_reverse($arr);
    $count count($arr);
    for(
    $i 0$i $count; ++$i) {
    $ret mysql_query("SELECT * FROM menu WHERE id = '".$arr[$i]."'");
    $row mysql_fetch_row($ret);
    $rent mysql_query("UPDATE sub_menu SET sub_id = sub_id - 1 WHERE sub_id > '".$row[2]."'");

    please if u have some better modus feel free to suggest me..
    thanx in advance!

  10. #10
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Lviv, Ukraine
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lilleman
    Hi,

    Perhaps you can use a query like the one below?

    Code:
    UPDATE table SET category = category-1 WHERE category > 3
    Hi!

    I have the same question.
    But I need replace data, for example:
    Code:
    +----------+------+
    | category | name |
    +----------+------+
    |        1     | 1      |
    |        2     | 2      |
    |        3     | 3      |
    |    -> 4     | 4      |
    |    -> 5     | 5      |
    |        6     | 6      |
    +----------+------+
    Replace category=4 and category=5
    Any suggestion

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem the script works perfectly..


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
  •