Jump to content

Recommended Posts

First off Im no Coder. I struggle through and make do most of the time, taking snippets I generally manage to get done what I need and edit.

 

Now I am totally perplexed by the task at hand.

 

Basically I have a small site with a handful of users. I want to check the dates the users login, I have a nice script I found which is calling for what I want. But it dsiplays in UNIXTIMESTAMP. For the life of me I cant figure out how to get it to display in GMT (or any "real" date).

 

I can call a date and convert it to GMT, but not when calling for the users database with and displaying all the logins from a table.

 

Help would be greatly appreciated.

 

Heres the snippet Im using.

function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/
Share on other sites

OK, thank you. I have gone about calling the date in a few ways, mostly to the result of what you supplied.

 

But the problem Im having is Im calling from my database for the users last login dates. I have it outputting the UNIX timestamp. Which looks like: 1254863670

 

Now I want to have that date displayed as a date we know it as.

 

Thats where Im getting stuck, I cant figure out how to call the dates and THEN convert it for all the dates.

 

Im sure it's that I have to add something with the $time var to have it display correctly

 

function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);

 

and

 

echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";

 

What I add there to get the var correct, I really dont know

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.