/    Sign up×
Community /Pin to ProfileBookmark

How would you do this in PHP?

Hello ppl
I want to be able to [B]copy[/B] a record [B]into the same MySQL table [/B]with only change in one column (C2 in this example). How would you do this?

Example
C1 is record number which is auto increment. I name the second column (from a form that client will fill) to Julie

ORIGINAL RECORD COLUMNS——-C1-C2-C3-C4-C5
VALUES————————–[COLOR=”Red”]01[/COLOR][B]Rose[/B]-22-34-52

COPIED RECORD COLUMNS——-C1-C2-C3-C4-C5
VALUES————————–[COLOR=”red”]02[/COLOR][B]Julie[/B]-22-34-52

[B]Basically I am trying to create what we have as SAVE AS in all Microsoft Applications. Saving a record with a different name (col2).
I am using MySQL and PHP[/B]

Thanks

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@cridleyDec 03.2007 — assuming C1 is identity column:

INSERT INTO Table_Name (SELECT null, 'Julie', C3, C4, C5 WHERE C1 = value)

value is the id of the record to copy.
Copy linkTweet thisAlerts:
@XTIauthorDec 03.2007 — I tried it but I am getting error message saying that [B]syntex is wrong[/B].
Copy linkTweet thisAlerts:
@XTIauthorDec 06.2007 — [B]Since somebody else in future might run into the smae problem and try to follow this thread I add this:[/B]

After a lot of experimenting with the code and not getting anywhere I checked in details in MySQL Help.

[B][COLOR="Red"]Apparently it is not possible to copy and insert into the SAME table in present version of MySQL.[/COLOR][/B]
Copy linkTweet thisAlerts:
@holidayDec 06.2007 — why couldn't you just do this

[code=php]
$new_name = "Julie";

$results = mysql_query("SELECT * FROM [TABLE] WHERE id='1' ");
$row = mysql_fetch_assoc($results);


mysql_query("INSERT INTO [TABLE] (C2, C3, C4, C5)
VALUES ('$new_name', '" . $row['C3'] . "', '" . $row['C4'] . "', '" . $row['C5'] . "') ");

[/code]
Copy linkTweet thisAlerts:
@DragonkaiDec 06.2007 — Yea, what holiday said. Just fetch the results as variables and input back again.
×

Success!

Help @XTI spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...