mysql row update question

Discussion in 'MySQL' started by izlik, Oct 29, 2007.

  1. #1
    Hello.

    Im running a gaming website where each game has the possibility to have keywords added to them. insteed of updating 2300 rows manually i was wondering if it is possible to somehow run a query that update the collumn "keyword" for all rows in the table, with what is writen in the row "name" in the same table ?
     
    izlik, Oct 29, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not sure what you mean, but you want a query to add a keyword to your keyword list?

    my head kinda hurts now, so if you know php/mysql i'll give you the idea and sample set, if not, well, maybe someone can come along and perfect it

    //get current value
    $connect =mysql_connect($dbname, $dbusername, $dbpass);
    $result=mysql_query("SELECT * from tablename WHERE value"); //unsure what you want here
    while($row=mysql_fetch_array($result)) {
    $row2=row."keyword";
       mysql_query("UPDATE keyword SET $row2 FROM tablename WHERE value=$row");
    }
    PHP:
    actually, that's very crude, and very basic, and most likely very unoptimized.

    im suffering from lack of sleep :(
     
    Lordy, Oct 29, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    im sorry if i made it confusing :) i want it to copy the text on each row on the collumn "name" for and copy it into each row for the collumn "keyword" for all 2300 rows. kinda like copy paste! :)

    how it looks like

    Name: horde jumping
    Keyword:

    what i want

    Name: horde jumping
    Keyword: horde jumping
     
    izlik, Oct 29, 2007 IP
  4. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Try this query:

    $result=mysql_query("UPDATE Tablename SET keyword = name");

    Replace Tablename with your actual name of table.
    Please note that this will replace all rows.

    You can also add a condition as

    $result=mysql_query("UPDATE Tablename SET keyword = name WHERE condition");
     
    Kuldeep1952, Oct 30, 2007 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5

    that worked perfectly, thank you! ;D
     
    izlik, Oct 30, 2007 IP