close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Record View Counter, Update Record, Increment

Thread began 4/21/2010 6:11 pm by dlovas275157 | Last modified 4/23/2010 4:25 pm by Jason Byrnes | 1272 views | 9 replies |

dlovas275157

Record View Counter, Update Record, Increment

When using ADDT, I created a record view counter. In my database, each record had a numeric column entitled viewCount. On page load (for a record's detail page), the page had a custom transaction as follows that would add 1 to the number in the viewCount column:

// Make a custom transaction instance
$countViews = new tNG_custom($conn_wmConn);
$tNGs->addTransaction($countViews);
// Register triggers
$countViews->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", "1");
// Set custom transaction SQL
$countViews->setSQL("UPDATE wm_inventory SET viewCount = viewCount + 1 WHERE id = {GET.id}");
// Add columns
// End of custom transaction instance

This would increment the viewCounter column in my database for that record by 1 when its detail page was loaded.

How can I go about setting up something similar with WebAssist's extensions? I have played around with adding an dataassist update record sb, but doesn't seem to work.

Thanks for any help.

D.

Sign in to reply to this post

Jason ByrnesWebAssist

On the bindings panel, click the plus button, an select URL variable. Set the name to id.


Then add the Data Assist Update record server behavior.

Set the trigger to "Before Page Load"

For the Key column select the id column. next to Key Column value, click the lightning bolt and select the id URL variable from the bindings list.


On the second page, select the viewCount column, then click the lightning bolt next to value. From the detail page recordset, select the viewCount column. This will add code similar to:

php:
<?php echo $row_RecordsetName['viewCount']; ?>



change that to:

php:
<?php echo $row_RecordsetName['viewCount']++; ?>




finally, make sure that the forms action will pass the id querystring when it posts, change the forms action to:

php:
<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""?>
Sign in to reply to this post

dlovas275157

Jason,

I followed up till the last step where it says "finally, make sure that the forms action will pass".

There is not a form on the page.

Sign in to reply to this post

Jason ByrnesWebAssist

d'ho, right, it's a detail page, the update occurs on load.

never mind the form action part.

Sign in to reply to this post

dlovas275157

It does not appear to be working. I have attached my page code.

The link to get my detail page is as follows (it passes 1 url parameter "gid") should i use it instead of "id" as in your example. I tried that as well but it did not work either.

detail.php?gid=978

Thanks again for your help.

Attached Files
detail.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

well, yes, if the page is using the gid query string, that is the one you will need to use in the update record behavior.


your sample code at the begining used "id" that is why I used that in the instructions:
$countViews->setSQL("UPDATE wm_inventory SET viewCount = viewCount + 1 WHERE id = {GET.id}");


to trouble shoot the problem, find:

php:
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());




and change it to:

php:
die($WA_Sql);

$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());



this will write the update SQL to the screen.


try using this sql directly on the database in PHPMyAdmin or some other MySQL GUI tool.

Sign in to reply to this post

dlovas275157

Jason,

Thanks for your patience. I have replace the code with the die code as your recommended. It outputs the following sql:

UPDATE `ws_inventory` SET `viewCount` = 1 WHERE `id_inventory`=980

viewCount is always output as equal to the current value in the database (not one over the current value)

If I run this on the database in PHPMYADMIN it sets the view count to 1 for that specific record (#980).

Attached are screenshots of update record wizard steps and code.

Attached Files
detail.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

using:
<?php echo $row_rsGuns['viewCount']++; ?>
should increment it by 1.

Maybe try explacitly ading 1 instead:

<?php echo $row_rsGuns['viewCount']+1; ?>

Sign in to reply to this post

dlovas275157

That worked!!

For some reason
<?php echo $row_rsGuns['viewCount']++; ?>
would not work for me....

Changing it to:
<?php echo $row_rsGuns['viewCount']+1; ?>
worked!!

Thanks for your patience and prompt replys.
D.

Sign in to reply to this post

Jason ByrnesWebAssist

excellent, glad to hear it is working.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...