Jump to content

History log


Norsk.Firefox

Recommended Posts

Hello,

I want to log a history of what my users do on my page. They are logged in, and I want to log when they post a message in another's guest book or something else. I've made a solution, I made a database where I log the user's ID, and other ID's, in example the submitted guestbook text ID.

But if I use my method I have to make one query where I get the history from the user, and then another query for every row, based on what is logged.

 

Not explained to well now.. So I tries with some code also.

Have this table:

CREATE TABLE `history` (
  `id` int(11) NOT NULL auto_increment,
  `time` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `type` smallint(6) NOT NULL,
  `under` smallint(6) NOT NULL,
  `val1` int(11) NOT NULL,
  `val2` int(11) NOT NULL,
  `val3` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;

 

And when I add a row to the database I use this function:

<?php
// (user id, type of history, type of type , a value, another value, and a third value if needed)
function HisLog($uid, $type, $under = 0, $val1 = 0, $val2 = 0, $val3 = 0) {
// Adds the row to the database
mysql_query("INSERT INTO `history` VALUES ('', '". time() ."', '". $uid ."', '". $type ."', '". $under ."',
							 '". validate($val1) ."',
							 '". validate($val2) ."',
							 '". validate($val3) ."')");
// Collect the time of the 25 row to be able to just allow 25 history-rows for every user
$mysql = mysql_query("SELECT `time` FROM `history` WHERE uid = '". $uid ."' AND type = '". $type ."' AND under = '". $under ."' 
							ORDER BY time DESC LIMIT 24, 1");
// Delete all superfluous rows
if(@mysql_result($mysql, 0) > 0)
	mysql_query("DELETE FROM `history` WHERE uid = '". $uid ."' AND time < '". mysql_result($mysql, 0) ."'");

}
?>

 

And when I then want to get the data from the database I have to get all the rows from the database, then get more info (Based on type, under and val1/2/3. So I have to use 26 queries if the user has 25 history logs.

 

Anyone have a better solution?

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.