SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacing values in Mysql

    In a table, I have |'s and '|''s
    Now I need to replace |'s with |^|'s and '|''s with |'s.

    How would I do this? I was think that maybe I'd have to extract it all then enter it again, but I have an edit article page, where I can do some eregi_replace's but I don't know what I should do to be able to replace these.

    any help?

    BTW, After each one, there is a 's so there really is one like '|'

    -Peter

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not entirely sure what or why your using those symbols, but you can grab the data from the table, store it in an array, then use this to replace it:
    PHP Code:
    <?
    $sql 
    "sql query here";
    $result mysql_query($sql$connect); // where connect is mysql_connect() stuff
    $row mysql_fetch_array($result);

    $new_value str_replace ("|""|^|"$row[column_name]);

    $update_sql ="UPDATE table_name SET new_vaule = '$new_value'";
    ?>
    and so on.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also use MySQL to do the REPLACE for you ....

    $yaks=mysql_query("UPDATE $table SET $column_name=REPLACE($column_name,'|','|^|')")or die(mysql_error());


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
  •