Adding counters to records in db (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


99bird -> Adding counters to records in db (3/19/2004 21:46:18)

I want to add a counter to all records in a db, so I can tell how many times a record is viewed. I found this post http://www.frontpagewebmaster.com/Adding_to_counters_to_records_in_db%3F%3F/m_64421/p_10/tmode_3/smode_1/tm.htm in searching the forum. Can someone explain how and where I would insert UPDATE table1 set TimesViewed= TimesViewed + 1 WHERE (ID = ::ID::) statement in a asp results page?

Thanks in advance for your assistance




BeTheBall -> RE: Adding counters to records in db (3/20/2004 10:00:55)

Welcome to Outfront.

If you are using the wizard, just open your page and insert a database results region above the one that shows the results. In step 2 of the wizard, select Custom Query and in the subsequent dialogue box, enter your SQL as above:

UPDATE table1 set TimesViewed= TimesViewed + 1 WHERE (ID = ::ID::)

In step 3, click "More Options and clear out the text box where "No records returned" appears. In step 4, uncheck the 3 check boxes and in step 5, mark "display all records together".

If you are using "Pure ASP", I would simply insert the code to perform the update at the very top of the page, even before the <head>.

Hope that helps.




99bird -> RE: Adding counters to records in db (3/20/2004 12:40:56)

Thanks Duane for the reply. I tried adding the second results region on the page as instructed and It didn't work. I get this error. "Database Results Error
The operation failed. If this continues, please contact your server administrator" on the page. Is the statement correct? Any suggestions? As for your second suggestion, How would I go about adding the statement? I don't have a clue! Could you or anyone steer me in the right direction.

Thanks again for your help.




BeTheBall -> RE: Adding counters to records in db (3/20/2004 14:58:29)

Follow the direction in this post to get the true error:

http://www.frontpagewebmaster.com/m-175524/mpage-1/key-operation%252Cfailed//tm.htm#175524




99bird -> RE: Adding counters to records in db (3/20/2004 15:20:36)

Duane.
I got it to work by changing the statement to UPDATE table1 SET TimesViewed = TimesViewed + 1 WHERE (ID = ID) but it updates the counts on every record in the database not just the induvidual record that is being viewed on the results page.
Any Ideas?

Al




BeTheBall -> RE: Adding counters to records in db (3/20/2004 15:31:57)

How are users getting to the results page? Via a link or by filling out a search form. Either way the code should not choke on ::ID::. What type of field is ID in the datebase? Hopefully numeric. Please go back to the previous code and follow the instructions in the link I gave you in my last post so we know what error is begin triggered. It appears that the ID is not being passed to the page. Also, if you have a link, please post it.




99bird -> RE: Adding counters to records in db (3/20/2004 19:27:55)

The users getting to the results page? Via a link.
newinv.asp?=<%=FP_FieldURL(fp_rs,"VehId")%>

Yes, the VehId and views fields in the datebase are numeric.

The statement UPDATE tblVehicles SET views= views + 1 WHERE (VehId = ::VehId::) now works without getting an error.
The error was due to s-columnnames and s-columntypes. So I added "VehId,views" in the s-columnnames and "3,3" in the s-columntypes. The error is now gone. But the count is not updated.

In the address bar when you go to the results page shows the infomation http://www.krenekrv.com/used/newinv.asp?VehId=439 on it brings up the proper results.

It soulds like you are correct in saying that the VehId is not being passed to the page where it can be picked up. Any other ideas?

Thanks again!
Al




BeTheBall -> RE: Adding counters to records in db (3/21/2004 12:16:58)

You too may want to try what I mentioned in my last post in this topic:

http://www.frontpagewebmaster.com/m-182756/tm.htm




99bird -> RE: Adding counters to records in db (3/23/2004 20:55:00)

Duane,
Finally got it working by adding s-columnnames and s-columntypes values and changing the statement as follows;
UPDATE tblVehicles SET [views]= views + 1 WHERE ([VehId] = ::VehId::)
Don't ask me how or why it works......but it works. However I did find that when I did a test page created from scrach in a test site using FP2002 it worked with out any changes. But in this site using FP2003 it didn't. In reaseaching, I have seen post about issues resulting from switching from FP2002 to FP2003 and this type of things.

Thanks again for all your help.




BeTheBall -> RE: Adding counters to records in db (3/23/2004 21:14:46)

Glad you got it going. In my humble opinion, MS owes all purchasers of FP 2003 a large refund. [:'(]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
7.788086E-02