This topic is locked

Last Activity of each user

10/5/2007 2:31:45 AM
PHPRunner General questions
D
dorlisa author

Hi All, (it's me again)
I was wondering how to add a last activity section to my menu page.

I want each members last activity on the site to be listed in a certain section.
I saw a sample of what I want it to look exactly__ like on this website...
Click Here for the Sample Website with the Last Activity section
Has anyone ever done this...
If so, can you help a sistah out.
Thanks,

phpnewbie

J
Jane 10/8/2007

Hi,
you can do it using custom event on the menu page.
Here are some advices:

  • create new tables and add all actions to this table. Use Before record added, Before record updated and other events.

    Here is a sample code:
    global $conn;

    $str = "insert into last_actions (Username, Action, DateOfAction) values ('".$_SESSION["UserID"]."','add new record to TableName', now())";

    $db_exec($str,$conn);


  • then select last ten records from last_actions table and display result on the menu page (using Custom event).

D
dorlisa author 10/8/2007

Hi Jane:
I think I have listed all the pieces to this, can you help me with this? It is so many pieces, i don't know where to begin (some of the stuff I knew how to code and most I didn't):
[indent]items //all of these items will have a resultnamelink, which is the third part of the action

after event added (in '_events' table)

after comment added (in '_image_comments' table)

after members added (in '_members' table)

after members_edit added (on '_members_edit' page)

after photo_name added (in '_photo_album' table)

after image_name added (in '_our_photos' table)

after res_name added (in '_restaurants' table)

after rest_comment added (in '_rest_comments' table)
_action table

added the picture

became a member

's member information changed

added the event

added the comment

added the restaurant

added the restaurant comment
_last_actions table

username

action (an action here has three parts (usernamelink + action + resultnamelink))

dateofaction
if 'new member or logged on member' performs an action in the _action table

add action to _last_actions table as (username,usernamelink + action + resultlink,dateofaction)
usernamelink = $value = "<a href=..._members_view.php?editid1=".$data["member_id"].">".$data["username"]."</a>";
resultnamelink goes to that persons added item =

event added name(_events_view.php)

comment added (_image_comment_list.php)

members added (_members_view.php)

members_edit added (_members_view.php)

photo_name added (_photo_album_view.php)

image_name added (_our_photos_view.php)

res_name added (_restaurants_view.php)

rest_comment added (_rest_comments_list.php)
Then comes your code:
global $conn;

$str = "insert into last_actions (Username, Action, DateOfAction) values ('".$_SESSION["UserID"]."','add new record to TableName', now())";

$db_exec($str,$conn);
then select last ten records from last_actions table and display result on the menu page (using Custom event). [/indent]

J
Jane 10/8/2007

Hi,
here is a sample code of "Before record added" event for the '_image_comments' table

global $conn;

//** select member id from members table ***

$strSelect = "select member_id from _members table where username='".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSelect,$conn);

$dataSelect = db_fetch_array($rsSelect);
$Action= "<a href=\"_members_view.php?editid1=".$dataSelect["member_id"]."\">".$_SESSION["UserID"]."</a>";

$Action.= " added the picture ";

$Action.= "<a href=\"_image_comments_list.php\">Link</a>";

$str = "insert into last_actions (Username, Action, DateOfAction) values ('".$_SESSION["UserID"]."','".$Action."', now())";

$db_exec($str,$conn);


Make the same for another tables.
Here are some helpful links:

http://ru2.php.net/manual/en/

http://webcheatsheet.com/php/

http://www.w3schools.com/php/default.asp

D
dorlisa author 10/8/2007

Thanks Jane...
I think this was the best link for beginners...http://www.w3schools.com/php/default.asp

I am studying it like a mad woman.
by the way...

I have all of those entered on their respective pages, but how do I display all of that info on the menu page in a certain section of the page?

J
Jane 10/9/2007

Hi,
to display result on the menu page use custom event on the menu page (Insert PHP code snippet option).

Here is a sample code:

global $conn;

$str = "select * from last_actions order by DateOfAction desc limit 10";

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

while ($data = db_fetch_array($rs))

echo $data["DateOfAction"].": ".$data["Username"]." ".$data["Action"]."
";

D
dorlisa author 10/9/2007

Hey Jane:
I got this error:
Error type: 256
Error description: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'table where username='dorlisa'' at line 1
URL: .../_image_comments_add.php?
Error file: .../include/dbconnection.php
Error line: 26
SQL query: insert into `_image_comments`
Solution: This is a general error. It occurs when thereis an error in event code or in SQL. Send your SQL or event code along with full error message tosupport@xlinesoft.com.
Here is the code I entered under _image_comments under custom code:

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//** Custom code ****

// put your custom code here
global $conn;

//** select member id from members table ***

$strSelect = "select member_id from _members table where username='".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSelect,$conn);

$dataSelect = db_fetch_array($rsSelect);
$Action.= "<a href=\"_members_view.php?editid1=".$dataSelect["member_id"]."\">".$_SESSION["UserID"]."</a>";

$Action.= " added the picture ";

$Action.= "<a href=\"_image_comments_list.php\">".$data["commentname"]."</a>";

$str = "insert into last_actions (username, action, dateofaction) values ('".$_SESSION["UserID"]."','".$Action."', now())";

$db_exec($str,$conn);
// return true if you like to proceed with adding new record

// return false otherwise

J
Jane 10/9/2007

Hi,
to debug your code print all queries on the page and then execute these queries in the database directly:

$strSelect = "select member_id from _members table where username='".$_SESSION["UserID"]."'";

echo $strSelect;

...

D
dorlisa author 10/9/2007

okay.....
i guess i am on my own with no clue how to execute any of that.
Thanks.