Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Updating Columns

Updating Columns

Scheduled Pinned Locked Moved Database
databasetutorialjavascriptphphtml
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    whatsa
    wrote on last edited by
    #1

    Currently I have a column in a MySQL database full of car makes such as Audi, Porsche, and BMW. Although, the make column is filled with either Audi or Audi® or Audi ® and for the other car makes. There are over 2000 rows. I'm trying to figure out how to make every row just "MAKE ®" without typing it because I'm using it to make a menu in php/javascript and it repeats menu items like "Audi" and "Audi®" and "Audi ®." http://i54.tinypic.com/w7zm6c.png I've tried SELECT DISTINCT but that just takes away the repeated makes, I need to change all the makes to follow the same format. For example I have.. $makes_select = "SELECT DISTINCT make FROM files_avail where shw=1 ORDER BY make"; // Fetching of makes I was looking up the MySQL Reference Pages like on here: http://dev.mysql.com/doc/refman/5.0/en/replace.html And query commands like UPDATE and INSERT. But I am unsure of how to do it in MySQL, I didn't want to do anything before I screw up the entire database :3 Thanks! -Faul

    L J 2 Replies Last reply
    0
    • W whatsa

      Currently I have a column in a MySQL database full of car makes such as Audi, Porsche, and BMW. Although, the make column is filled with either Audi or Audi® or Audi ® and for the other car makes. There are over 2000 rows. I'm trying to figure out how to make every row just "MAKE ®" without typing it because I'm using it to make a menu in php/javascript and it repeats menu items like "Audi" and "Audi®" and "Audi ®." http://i54.tinypic.com/w7zm6c.png I've tried SELECT DISTINCT but that just takes away the repeated makes, I need to change all the makes to follow the same format. For example I have.. $makes_select = "SELECT DISTINCT make FROM files_avail where shw=1 ORDER BY make"; // Fetching of makes I was looking up the MySQL Reference Pages like on here: http://dev.mysql.com/doc/refman/5.0/en/replace.html And query commands like UPDATE and INSERT. But I am unsure of how to do it in MySQL, I didn't want to do anything before I screw up the entire database :3 Thanks! -Faul

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Member 7723899 wrote:

      I didn't want to do anything before I screw up the entire database

      then make a backup first. or at least copy the relevant table to a new one. if you have PHPmyAdmin, both actions would be very easy.

      Member 7723899 wrote:

      make every row just "MAKE ®"

      a single update could remove every trailing ® in all rows that have one then a single update could remove every trailing space in all rows that have one then a single update could append whatever you want in all rows BTW: I see no use of a suffix " ®" that would be present in every row, it does not add information, it just makes things more difficult IMO. And if you want it to appear on some forms, then that is a presentation issue, something a database should not be involved in. Note: we have a separate MySQL forum! :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      W 1 Reply Last reply
      0
      • W whatsa

        Currently I have a column in a MySQL database full of car makes such as Audi, Porsche, and BMW. Although, the make column is filled with either Audi or Audi® or Audi ® and for the other car makes. There are over 2000 rows. I'm trying to figure out how to make every row just "MAKE ®" without typing it because I'm using it to make a menu in php/javascript and it repeats menu items like "Audi" and "Audi®" and "Audi ®." http://i54.tinypic.com/w7zm6c.png I've tried SELECT DISTINCT but that just takes away the repeated makes, I need to change all the makes to follow the same format. For example I have.. $makes_select = "SELECT DISTINCT make FROM files_avail where shw=1 ORDER BY make"; // Fetching of makes I was looking up the MySQL Reference Pages like on here: http://dev.mysql.com/doc/refman/5.0/en/replace.html And query commands like UPDATE and INSERT. But I am unsure of how to do it in MySQL, I didn't want to do anything before I screw up the entire database :3 Thanks! -Faul

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Member 7723899 wrote:

        I've tried SELECT DISTINCT but that just takes away the repeated makes, I need to change all the makes to follow the same format

        The steps are 1. Determine what values are in there 2. Determine what values should be in there. 3. Create an algorithmic solution that will convert an incorrect value to a correct one. This is based on steps 1 and 2. 4. Implement 3 in SQL. 5. Run 4. Your description sounds like you have not completed steps 1 and 2 in the above and are attempting to jump directly to step 4. Additionally. 1. Determine if you want to prevent future incorrect values 2. If yes then add a constraint that prevents incorrect values. Based on your description you would do this by creating an enumeration table which is nothing but a table of correct names. Then you use a foreign key from the existing table to the enumeration table.

        P 1 Reply Last reply
        0
        • J jschell

          Member 7723899 wrote:

          I've tried SELECT DISTINCT but that just takes away the repeated makes, I need to change all the makes to follow the same format

          The steps are 1. Determine what values are in there 2. Determine what values should be in there. 3. Create an algorithmic solution that will convert an incorrect value to a correct one. This is based on steps 1 and 2. 4. Implement 3 in SQL. 5. Run 4. Your description sounds like you have not completed steps 1 and 2 in the above and are attempting to jump directly to step 4. Additionally. 1. Determine if you want to prevent future incorrect values 2. If yes then add a constraint that prevents incorrect values. Based on your description you would do this by creating an enumeration table which is nothing but a table of correct names. Then you use a foreign key from the existing table to the enumeration table.

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          No, no, no... The steps are 0) Put your left foot in 1) Take your left foot out 2) Put your left foot in 3) Shake it all about 4) Do the hokey pokey

          1 Reply Last reply
          0
          • L Luc Pattyn

            Member 7723899 wrote:

            I didn't want to do anything before I screw up the entire database

            then make a backup first. or at least copy the relevant table to a new one. if you have PHPmyAdmin, both actions would be very easy.

            Member 7723899 wrote:

            make every row just "MAKE ®"

            a single update could remove every trailing ® in all rows that have one then a single update could remove every trailing space in all rows that have one then a single update could append whatever you want in all rows BTW: I see no use of a suffix " ®" that would be present in every row, it does not add information, it just makes things more difficult IMO. And if you want it to appear on some forms, then that is a presentation issue, something a database should not be involved in. Note: we have a separate MySQL forum! :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            W Offline
            W Offline
            whatsa
            wrote on last edited by
            #5

            I found it out. Simple enough.. I was just only wondering WHERE I should make the SQL code. I'm using SQL Manager Lite for MySQL and you just have to go to the database table, click the DLL tab, edit, delete all the code and write whatever you want and execute.

            UPDATE tablename SET columnname = 'whatever' WHERE columname = 'asdf' OR columname = 'asdf ®'

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups