On 9/12/00, Peter Benoit penned:
>I have 2 tables, which have a relationship of the unique ID. I'm kind of
>confused how to update table 2, with a matching record from table 1.
>
>For instance, if table 1 was products, and table 2 was a download count of
>those products. Each time it's downloaded, I need to update the product
>count in table 2 according to which product it is in table 1. Make sense?
>
>Not sure how to go about this, any suggestions please?
Two ways to go about it. Enter a record into downloads when you enter
the product into products.
<CFQUERY DATASOURCE="mydatasource">
INSERT INTO products
(product_id,column2,column3,etc)
VALUES
(#product_id#,#column2#,#column3#,#etc#)
</CFQUERY>
<CFQUERY DATASOURCE="mydatasource">
INSERT INTO downloads
(product_id,downloadcount)
VALUES
(#product_id#,0)
</CFQUERY>
Then when they download:
<CFQUERY DATASOURCE="mydatasource">
UPDATE downloads
SET downloadcount = downloadcount + 1
WHERE product_id = #product_id#
</CFQUERY>
Or let them do it on the fly.
<CFQUERY DATASOURCE="mydatasource" NAME="indownloads">
SELECT product_id
FROM downloads
WHERE product_id = #product_id#
</CFQUERY>
<CFIF downloads.recordcount IS "0">
<CFQUERY DATASOURCE="mydatasource">
INSERT INTO downloads
(product_id,downloadcount)
VALUES
(#product_id#,1)
</CFQUERY>
<CFELSE>
<CFQUERY DATASOURCE="mydatasource">
UPDATE downloads
SET downloadcount = downloadcount + 1
WHERE product_id = #product_id#
</CFQUERY>
</CFIF>
--
Bud Schneehagen - Tropical Web Creations
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.