UPDATE instead of INSERT INTO
UPDATE instead of INSERT INTO
am 05.09.2009 22:19:25 von Ron Piggott
------=_NextPart_000_001F_01CA2E44.A2A72FC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I made an application which lets users rate web site content. At the =
heart of the application is this mySQL query:=20
INSERT INTO `ratings` ( `reference` , `content_type` , =
`content_reference` , `language` , `ip_address` , `rating_timestamp` , =
`rating` ) VALUES ( NULL , '$content_type','$content_reference' , =
'$language', '$ip_address', NOW( ) , '$user_rating' );=20
I am wondering if there is a way to check if the user has already voted =
(IE If there is already a matching record with the same content_type, =
content_reference, language, ip_address values) so all that happens is =
an UPDATE to the rating field?
Ron
------=_NextPart_000_001F_01CA2E44.A2A72FC0--
Re: UPDATE instead of INSERT INTO
am 05.09.2009 22:45:52 von Waynn Lue
INSERT INTO ON DUPLICATE KEY UPDATE is what you're looking for.
On 9/5/09, Ron Piggott wrote:
> I made an application which lets users rate web site content. At the heart
> of the application is this mySQL query:
>
> INSERT INTO `ratings` ( `reference` , `content_type` , `content_reference` ,
> `language` , `ip_address` , `rating_timestamp` , `rating` ) VALUES ( NULL ,
> '$content_type','$content_reference' , '$language', '$ip_address', NOW( ) ,
> '$user_rating' );
>
> I am wondering if there is a way to check if the user has already voted (IE
> If there is already a matching record with the same content_type,
> content_reference, language, ip_address values) so all that happens is an
> UPDATE to the rating field?
>
> Ron
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: UPDATE instead of INSERT INTO
am 06.09.2009 01:40:03 von Ron Piggott
Thanks
----- Original Message -----
From: "Waynn Lue"
To: "Ron Piggott" ;
Sent: Saturday, September 05, 2009 4:45 PM
Subject: Re: [PHP-DB] UPDATE instead of INSERT INTO
> INSERT INTO ON DUPLICATE KEY UPDATE is what you're looking for.
>
> On 9/5/09, Ron Piggott wrote:
>> I made an application which lets users rate web site content. At the
>> heart
>> of the application is this mySQL query:
>>
>> INSERT INTO `ratings` ( `reference` , `content_type` ,
>> `content_reference` ,
>> `language` , `ip_address` , `rating_timestamp` , `rating` ) VALUES ( NULL
>> ,
>> '$content_type','$content_reference' , '$language', '$ip_address', NOW( )
>> ,
>> '$user_rating' );
>>
>> I am wondering if there is a way to check if the user has already voted
>> (IE
>> If there is already a matching record with the same content_type,
>> content_reference, language, ip_address values) so all that happens is an
>> UPDATE to the rating field?
>>
>> Ron
>>
------------------------------------------------------------ --------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.409 / Virus Database: 270.13.78/2347 - Release Date: 09/05/09
05:51:00
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: UPDATE instead of INSERT INTO
am 09.09.2009 01:29:10 von Daevid Vincent
http://dev.mysql.com/doc/refman/5.0/en/replace.html
Or as previously mentined:
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.h tml
> > -----Original Message-----
> > From: Ron Piggott [mailto:ron.php@actsministries.org]
> > Sent: Saturday, September 05, 2009 1:19 PM
> > To: php-db@lists.php.net
> > Subject: [PHP-DB] UPDATE instead of INSERT INTO
> >
> > I made an application which lets users rate web site content.
> > At the heart of the application is this mySQL query:
> >
> > INSERT INTO `ratings` ( `reference` , `content_type` ,
> > `content_reference` , `language` , `ip_address` ,
> > `rating_timestamp` , `rating` ) VALUES ( NULL ,
> > '$content_type','$content_reference' , '$language',
> > '$ip_address', NOW( ) , '$user_rating' );
> >
> > I am wondering if there is a way to check if the user has
> > already voted (IE If there is already a matching record with
> > the same content_type, content_reference, language,
> > ip_address values) so all that happens is an UPDATE to the
> > rating field?
> >
> > Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php