PDA

View Full Version : Last Visited



jnscollier
03-11-2007, 04:20 PM
On the top of this page it shows the date and time I last visited... Anyone know of where I can find a script for a feature like this?

I want to put the date and time of the members' last logins on their profiles

Any help would be appreciated...
Thanks!
-Sammy

BLiZZaRD
03-11-2007, 04:25 PM
Would this be in a forum or another "profile" on your site?

If a forum, which type are you running?

jnscollier
03-11-2007, 04:31 PM
Well, I don't think you'd classify my site as a forum. It's basically a blogging site... I think thats the best way to classify it.
Basically, if you go to www.StupidPeoplePissMeOff.com (http://www.StupidPeoplePissMeOff.com), Click on one of the new members, a box should pop up with any profile info they have filled out, I'd like their last log in date and time to show there.

BLiZZaRD
03-11-2007, 04:52 PM
Okay I am not very good at this, but basically you will have to go into your MySQL database and figure out which table stores the log in information, specifically the time field.

Then you will have to pull that out with php, and show it on the page.

Something like this should get you started:



<?php
/* Data of SQL-server */
$server= "localhost"; /* Address database server */
$user= "xxxxxx"; /* Database username */
$password= "yyyyyyy"; /* Database Password */
$database= "dbxxxxxx"; /* name of database */
$table= "zzzzzzz"; /* Name of table, you can select that */

/* Accessing SQL-Server and querying table */
MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
$result=MYSQL_QUERY( "SELECT * FROM $table order by name");

/* Output data into a HTMl table */
echo "<table border=\"1\" align=center width=50&#37;";
echo "<tr>";
echo "<div color=\"#ffff00\">";
while ($field=mysql_fetch_field($result)) {
echo "<th>$field->name</A></th>";
}
echo "</font></tr>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
for($i=0; $i < mysql_num_fields($result); $i++) {
echo "<td align=center>$row[$i]</td>";
}
echo "</tr>\n";
}
echo "</table><BR><BR>";

/* Close SQL-connection */
MYSQL_CLOSE();
?>

jnscollier
03-11-2007, 04:58 PM
thanks!! i'll try it out... :)

BLiZZaRD
03-11-2007, 05:04 PM
It may not work exactly right, as I said SQL is NOT my thing. If you have further problems you can take this question and posted code to the SQL board and perhaps testingsite or Twey can further get it tweaked for you :D

thetestingsite
03-11-2007, 05:49 PM
Im not 100&#37; sure, but pretty sure that the functions like "mysql_connect", "mysql_[insert_line_here]" should be lowercase. Other than that, should work (although not tested). Let us know if you get any errors or need help tweaking it.

jnscollier
03-11-2007, 06:22 PM
I'll keep you guys posted on the results.. thanks a bunch :)

BLiZZaRD
03-11-2007, 06:32 PM
Im not 100% sure, but pretty sure that the functions like "mysql_connect", "mysql_[insert_line_here]" should be lowercase. Other than that, should work (although not tested). Let us know if you get any errors or need help tweaking it.

Yes I believe they should be lowercase. Sorry, this is from an old php3 script :o

jnscollier
05-22-2007, 05:41 PM
Right now I have nothing recording users log in times or dates, so I guess that's where I need to start... How can I track this?

Thanks in advance!

jnscollier
05-24-2007, 11:33 PM
i created a log in table and added the following code to the action page of my login. I don't know if this is the best code, but this is what i did and it works. For anyone who is curious...

i just wanted to track their last login, and i also threw in a "counter" for the number of times total that they've logged in (for own purposes)




$logintmemberid=$HTTP_SESSION_VARS["retailID"];

$lastlogin = date("Y-m-d H:i:s");

$searchlog="select logintmemberid from ".LOGIN." where logintmemberid = '".$logintmemberid."' ";
$searchres=mysql_query($searchlog)or die("Error".mysql_error());
$searchrows=mysql_num_rows($searchres);
if($searchrows > 0){

$updatelog="update ".LOGIN." set logincount=logincount+1, lastlogin='".$lastlogin."' where logintmemberid='$logintmemberid'";
mysql_query($updatelog) or die("Could not update login info");

}
else

{


$searchlog="INSERT into ".LOGIN." (logintmemberid,lastlogin,logincount) values('$logintmemberid','$lastlogin','1')";
mysql_query($searchlog) or die("Could not insert log info".mysql_error());

}