This topic is locked

Record Viewed Date

7/19/2005 2:42:59 PM
PHPRunner General questions
author

Hello - I think your product is fantastic. Question - I have created an app that only allows users to list a record. I have a "date viewed" field for each record I would like to update with the date they viewed it. Can I do this in SQL?

Sergey Kornilov admin 7/20/2005

Bob,
open ..._view.php and find the following code snippet:

LogInfo($strSQL);

$rs=db_query($strSQL,$conn);

$data=db_fetch_array($rs);


Add this code right after it:

$updateSQL = "update table1 set viewed=now()";

$updateSQL = AddWhere($updateSQL,$where);

db_exec($updateSQL,$conn);


In this example table1 - is your table name and viewed is the field where last view date is keeping.

500301 7/20/2005

Thanks, Sergey. I added the code, but don't see the field being updated. No error message either. Is it because I disabled 'view' in my app, and am only running 'list'? If so, can I modify _list.php with the same snippet?

500302 7/20/2005

Sergey, I've gotten your code to work by adding "view" mode... but now users have to click on list screen first and then view screen (the field I'm displaying is a hyperlink). Any way to put your code in _list.php, or to skip list screen and go straight to view screen?
Thanks!

Sergey Kornilov admin 7/22/2005

Bob,
you can modify ..._list.php following way.
Find this snippet

while(($data=db_fetch_array($rsData)) && $iNumberOfRows<$nPageSize)

{


and insert this code right after it.

$where = AddFieldWrappers($strKeyField)."=".make_db_value($strKeyField,$data[$strKeyField]);

if ($strKeyField2)

$strSQL.=" and ".AddFieldWrappers($strKeyField2)."=".make_db_value($strKeyField2,$data[$strKeyField2]);

if ($strKeyField3)

$strSQL.=" and ".AddFieldWrappers($strKeyField3)."=".make_db_value($strKeyField3,$data[$strKeyField3]);
$updateSQL = "update table1 set viewed=now()";

$updateSQL = AddWhere($updateSQL,$where);

db_exec($updateSQL,$conn);