close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Count Image Views

Thread began 12/13/2018 4:26 am by administration282761 | Last modified 12/14/2018 3:32 pm by Ray Borduin | 42 views | 8 replies |

administration282761

Count Image Views

I have a simple image rotation recordset for an advert image or banner:

<?php
$rsAdverts = new WA_MySQLi_RS("rsAdverts",$mysqli2,1);
$rsAdverts->setQuery("SELECT * FROM adverts ORDER BY RAND ()");
$rsAdverts->execute();
?>

In the DB table I have a INT column for "advert_views" which needs to be updated each time an image is displayed.

I would like to count the number of views for a particular image and incrementally update the "advert_views" column in the "adverts" table so that I can display this number..

Can this be done in the recordset or do I need to have some "trigger" on the page in the PHP code that displays the image that updates the table? Or both?

Update:

I tried this recordset but it causes a MYSQL error:

<?php
$rsAdverts = new WA_MySQLi_RS("rsAdverts",$mysqli2,1);
$rsAdverts->setQuery("SELECT * FROM adverts ORDER BY RAND () UPDATE adverts.advert_views SET adverts.advert_views = adverts.advert_views + 1");
$rsAdverts->execute();
?>

Thanks

Sign in to reply to this post

Ray BorduinWebAssist

You could use the MySQLi Update Record server behavior to increment the value. Use the Unique ID from the rsAdverts recordset to identify the row to update and increment the value of the advert_views. Use the "always" or "before page loads" (same thing) trigger and just make sure the update code appears below your recordset code (you will probably have to cut and paste to move it below).

Sign in to reply to this post

administration282761

Thanks
However the images are currently being displayed throughout the website as banner ads with several different sizes on each of the pages and not in a form.

Would I need to install a hidden form with the Update Record server behavior on each page that would trigger the update?

Sign in to reply to this post

Ray BorduinWebAssist

You don't need a form to trigger an update. You can just have the update code below the recordset anywhere you want the number incremented. No need for any forms or hidden form elements, just update from the recordset directly.

Sign in to reply to this post

administration282761

Ah - OK!

I tried this but it is not updating the advert_views - so I am missing the proper binding or the increment function..

<?php
$rsAdverts = new WA_MySQLi_RS("rsAdverts",$mysqli2,1);
$rsAdverts->setQuery("SELECT * FROM adverts WHERE adverts.advert_activate = '1' ORDER BY RAND ()");
$rsAdverts->execute();?>
<?php
if ("" === "") {
$UpdateQuery = new WA_MySQLi_Query($mysqli2);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "adverts";
$UpdateQuery->bindColumn("advert_views", "i", "1", "WA_DEFAULT");
$UpdateQuery->addFilter("advert_id", "=", "i", "".($_GET['advert_id']) ."");
$UpdateQuery->execute();
$UpdateGoTo = "";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>

Thanks

Sign in to reply to this post

Ray BorduinWebAssist

You should be getting the values from the Recordset, so it would be something like:

php:
<?php

if ("" === "") {
$UpdateQuery = new WA_MySQLi_Query($mysqli2);
$UpdateQuery->Action "update";
$UpdateQuery->Table "adverts";
$UpdateQuery->bindColumn("advert_views""i""".($rsAdverts->getColumnVal('advert_views')+1) ."""WA_DEFAULT");
$UpdateQuery->addFilter("advert_id""=""i""".($rsAdverts->getColumnVal('advert_id')) ."");
$UpdateQuery->execute();
$UpdateGoTo "";
if (
function_exists("rel2abs")) $UpdateGoTo $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>
Sign in to reply to this post

administration282761

Great. ! That works.!

I will put the entire code into an include file which can be applied throughout the website.

Yes, I was trying to figure out how to implement the "+1" in the increment code.

Now - if one could add a function for counting "Clicks" and a feature to e-mail the statistics to the users you would have a Webassist PRE-Built rotating banner application!

I learned a lot today.

Many thanks again, Ray!

Sign in to reply to this post

Ray BorduinWebAssist

I could help you implement those things. They are certainly possible to do, and not that difficult. Maybe a premier ticket to show you how. I think it would only take about an hour.

Sign in to reply to this post

administration282761

Thanks for your help and your offer. That would be really cool!

I will surely take you up on that offer as soon as I finish the current application and the client interface on the new site.

Sign in to reply to this post

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...