Re: Duplicating a Record in MySQL
| From: | David McInnis | Date: | Sun, 20 Oct 2002 05:36:58 +0000 |
| Subject: | Re: Duplicating a Record in MySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120658@lists.php.net to get a copy of this message | ||
Even if you select from an alias of the same table?
insert into tablex from (select * from tablex tabley)
David
----- Original Message -----
From: "Roger Lewis" <re.lewis@attbi.com>
To: "David McInnis" <david@dataovation.com>
Sent: Saturday, October 19, 2002 7:41 PM
Subject: RE: [PHP] Duplicating a Record in MySQL
> Yes, but you can't insert into the same table from which you select.
> Roger
>
> -----Original Message-----
> From: David McInnis [mailto:david@dataovation.com]
> Sent: Saturday, October 19, 2002 6:28 PM
> To: Roger Lewis; holmes072000@charter.net; 'Php-General'
> Subject: Re: [PHP] Duplicating a Record in MySQL
>
> Well, I confess that I have not read the entire thread. But MySQL does
> provide a INSERT from SELECT syntax which I have used often.
>
> David
>
> ----- Original Message -----
> From: "Roger Lewis" <re.lewis@attbi.com>
> To: <holmes072000@charter.net>; "'Php-General'"
<php-general@lists.php.net>
> Sent: Saturday, October 19, 2002 1:45 PM
> Subject: RE: [PHP] Duplicating a Record in MySQL
>
>
> >
> >
> > -----Original Message-----
> > From: John W. Holmes [mailto:holmes072000@charter.net]
> > Sent: Saturday, October 19, 2002 12:52 PM
> > To: 'Roger Lewis'; 'Php-General'
> > Subject: RE: [PHP] Duplicating a Record in MySQL
> >
> > * >> It's not strictly php, but does anyone know an easy way to
> > duplicate a
> > > >> record in MySQL. It would be nice if you could write something
> > like:
> > > >>
> > > >> COPY * from table WHERE id = 6;
> > > >>
> > > >> and have it insert a new record into the table with the next id
> > > >>number.
> > >
> > > >I think that if you have to do this, you've got design issues. Why
> > not
> > > >just keep a "count" column in the row and increment that, instead of
> > > >duplicating the row.
> > >
> > > >---John Holmes...
> > > John,
> > > Here's the application: I'm creating a daily report online, eg. with
> > > Title,
> > > Report no., Date, Author, Subject Headings, Text, etc., etc.. The
> > report
> > > is
> > > stored in a MySQL table. When it comes time to write a new report, I
> > > would
> > > like to be able to call up an existing report, upon which to base the
> > new
> > > one, and copy the record. Then make changes where necessary and
> > update
> > > the
> > > record.
> >
> > So have PHP select out the row you want to "copy", make your changes to
> > it with PHP or a form, then have PHP insert a new row into the database.
> > Why copy data when you're going to change it.
> >
> > ---John Holmes...
> > Well, you're probably right. I've been working with Adobe GoLive, and
> have
> > been using the CopyFormData command, so that's where I got the idea. I
> ran
> > into trouble with GoLive when I complicated my report form by adding
file
> > attachments. Anyway, here's a condensed version of code base on what
> > Stephen Knight suggested. (Thanks, Stephen). I'll work on this to try
> and
> > avoid the copying step as you are suggesting.
> >
> > $sql = "select * from daily_reports where report_no = '$report_no' ";
> > $result = mysql_query($sql);
> > $x = mysql_fetch_row($result);
> > $fields = "report_no, order_no, report_date, project_no, project_name,
> > client, title, subtitle, author, company, summary_heading,
> > summary, section1_heading, section1";
> > $values = " '$x[1]', '$x[2]', '$x[3]',
> > '$x[4]', '$x[5]', '$x[6]',
'$x[7]',
> > '$x[8]',
> > '$x[9]', '$x[10]', '$x[11]', '$x[12]',
> > '$x[13]', '$x[14]' ";
> > // Note: There must be a way to have PHP generate the previous line,
but
> I
> > don't know how.
> > $sql = "INSERT INTO daily_reports ($fields) VALUES ($values)";
> > mysql_query($sql);
> >
> > Thanks, Roger
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
>
>
>
>