SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP Select row from MySQL DB help plz!

    Hi

    I am trying to set up a query which will select rows from a mysql db based on certain criteria. Once the rows are selected I need to then duplicate the row but with one value changed in the last column.

    Can anyone tell me how I would go about doing this?

    I can set up the select statement to choose the rows I need to based on certain criteria but I don';t know how to do the duplication part. Any help would be much appreciated.

    Thanks in advance.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,328
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    select one row to be duplicated, or duplicate all rows that are returned by the query?

    you will have to give more information (table layout, example query, etc.) if you want anything more detailed

    otherwise all i can tell you is that you would do the duplication part with an INSERT statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    To duplicate a row in mysql you can use this syntax:
    Code:
    INSERT INTO targetTable (field1, field2) (SELECT field1, field2 FROM sourceTable WHERE condition=check)
    Try look on the net for "mysql duplicate and update row" .
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,328
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i would not code the parentheses around the SELECT clause of the INSERT, but apparently in mysql it still works
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •