SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with sql query

    I am a complete newbie at this and really do not know sql. I am just stumbling around but have completed a few queries with success. I have a field in a table that I want to APPEND information to, specifically the text " 7" (Without the quotes) I am using this:
    Code:
    INSERT INTO jos_vm_product product_sku VALUES ' 7'
    But I keep getting an error.

    I am using phpMyAdmin

    Can anyone offer some help here. This would save me hours of work.

    Many thanks,
    Houston
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try

    INSERT INTO jos_vm_product (product_sku) VALUES (7)

  3. #3
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got this error:
    Code:
    You have an error in your SQL syntax; check the manual that corresponds  to your MySQL server version for the right syntax to use near 'RT INTO  jos_vm_product (product_sku) VALUES (7)' at line 1
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the syntax

    INSERT INTO TABLENAME (COLOUMNAME) VALUES (VALUES)

    try
    INSERT INTO jos_vm_product (product_sku) VALUES ('7')

    are yu sure the table name is correct

  5. #5
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked but instead of appending a field in a record it added a whole new record. The filed product_sku was set to 7 and all other fields to NULL. Not was I was wanting to do.
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then u must use update statement

    Update tablename set coloumname=value

  7. #7
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wont this replace what is there? I just need it to append to what is already in the field
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then you should use concatenate for that particular coloumn and row

    update tablename set coloumname=concat(coloumname, '7') where id='1';

    id is the primary key

  9. #9
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did a slight modification but it worked. Many many thanks for your help.
    Code:
    update jos_vm_product set product_sku=concat(product_sku, ' 7') where product_id>'106'
    I have another thing I am wanting to accomplish it will make a lot more sense to do it using queries than doing through the Virtuemart interface. I have a client that wants to show 50 stone sizes and instead of just putting in all the stones once and using an option to choose one of the four sizes to order, he wants to show 50 stones in a 7mm category, 50 stones in a 8mm category, 50 stones in a 10mm category, 50 stones in a 12mm category. I advised against it but he is insistent. So now since I do not want to enter 150 stones back into the database using the VM admin, I figured there is some way to insert a copy each of the stones back into the database using a query. So basically there will be four of each kind and then I will go back and add 7mm, 8mm, 10mm, and 12mm to the end of the names to show the difference.

    Any suggestions on how I would do that?

    Cheers,
    Houston
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad it helped, can you ask your second question in a seperate thread


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
  •