May 18 2012 08:48:16
Languages
Navigation
Friends & Affiliates
Roadmap
[N] User Profile Wall
[N] Error log like in P...
[N] Submit photo - Subc...
[N] Warnings - who can ...
[N] [edit profile]Save ...
[N] Moving panels with ...
[N] Forum thread deform...
[N] Thumbnails in downl...
[N] [Locale German] New...
[N] Warnings only for a...
Users Online
· Guests Online: 8

· Members Online: 0

· Total Members: 490
· Newest Member: malgorzatka89
Last Seen Users
· xxyy17:15:51
· lilin0402 1 day
· angel 2 days
· vaesir 4 days
· malgorzatka89 1 week
· Iput23 1 week
· djdandi 1 week
· Cerplyt 1 week
· uygarozan 1 week
· sgejido 1 week

Login
 Username  Password  
View Thread: New Panel/Infusion
Who is here? 2 Guests
 Print Thread
New Panel/Infusion
Grimloch
Hey guys.I'm working on a new infusion that will be compatible with PiF as well as regular 7.01 ... If anyone can help me I sure would appreciate it. I've run into a problem that I cannot seem to solve. No one at Mods-Net seems to be able (or willing I'm not sure which), to help out and I thought I'd try here. It should be simple and I thought it was but here is my problem:

I need to extract from the database, the usernames that logged on the PREVIOUS day using the 'user_lastvisit' field. Here is a code snippet where the problem lies:

Download source  Code
<?php

$yesterday = date("m-d-Y", mktime(0, 0, 0, date("m"), date("d")-1, date("Y")));
$visited = $yesterday;
$result = dbquery("SELECT user_id, user_name, DATE_FORMAT(user_lastvisit, '$visited') AS my_day FROM ".DB_USERS." WHERE user_lastvisit = '$my_day' AND user_status='0' ORDER BY user_lastvisit DESC");

echo "[";
$i = 0;
if (dbrows($result) != 0) {
   while ($data = dbarray($result)) {
      $i++;
      echo "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' title='".$data['user_name']."'>".$data['user_name']."</a>";
      if ($i < dbrows($result)) { echo "] ["; }
   else { echo ""; }
   }
}
echo "]<br /><br />";
echo $visited;
?>




When I preview this in a custom page it displays 88 names from my userbase when in fact I know (at least today), that it should display 3 names as there were 3 logins yesterday. Time/Date conversions have always driven me crazy trying to figure out! I know the problem must be in the way I'm telling MySql to read the data but I just cannot figure it out. I've tried many many different configurations here and none seem to work right.

PS: The echo $visited; at the bottom DOES display yesterdays date correctly i.e.
06-22-2010
Edited by Grimloch on 23-06-2010 22:35
SignatureEnergy can neither be created nor destroyed; only transformed.
 
http://www.whisperwillow.com
Grimloch
keddy wrote:
I'll try to solve your problem tomorrow morning. Like you said... should be something simple but... isn't.


Hey keddy. I appreciate your attempt here but I think I have finally solved it and it WAS very simple actually. I did a LOT of online research and finally found the answer on a phpBB board. This is the final result which DOES work and displays users who logged on yesterday(last 24hrs):

Download source  Code
<?php

$result = dbquery("SELECT user_id, user_name, user_lastvisit FROM ".DB_USERS." WHERE user_lastvisit >= (UNIX_TIMESTAMP(CURDATE()) -86400)  AND user_status = '0' ORDER BY user_lastvisit DESC");
echo "[";
$i = 0;
if (dbrows($result) != 0) {
   while ($data = dbarray($result)) {
      $i++;
      echo "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' title='".$data['user_name']."'>".$data['user_name']."</a>";
      if ($i < dbrows($result)) { echo "] ["; }
   else { echo ""; }
   }
}
echo "]\n";

?>




Turns out there is no need for esoteric/manipulative date/time conversions as the (UNIX_TIMESTAMP(CURDATE()) -86400) function does it all. You simply subtracting 86400 seconds from the 'user_lastvisit' field which is from midnight of the previous day to midnight lastnight. If you preview this in a custom page you'll see that it works correctly.

Thanks again for volunteering to help. I can now finish my center panel.

:D
Edited by Grimloch on 24-06-2010 15:54
SignatureEnergy can neither be created nor destroyed; only transformed.
 
http://www.whisperwillow.com
Dallas
Nice work Grim
 
http://dtawebdesigns.com/
Grimloch
Dallas wrote:
Nice work Grim


Thanks; but actually after several days of observation, the above code doesn't quite work right. The following code however does work:

Download source  Code
$result = dbquery("SELECT user_id, user_name, user_lastvisit FROM ".DB_USERS." WHERE user_lastvisit > (UNIX_TIMESTAMP(CURDATE()) -86400) AND user_lastvisit < (UNIX_TIMESTAMP(CURDATE())) AND user_status = '0' ORDER BY user_lastvisit DESC");
echo "[";
$i = 0;
if (dbrows($result) != 0) {
   while ($data = dbarray($result)) {
      $i++;
      echo "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' title='".$data['user_name']."'>".$data['user_name']."</a>";
      if ($i < dbrows($result)) { echo "] ["; }
   else { echo ""; }
   }
}




I needed to be able to specify a range. Supposedly there is a MySql command called BETWEEN but I could find no reference or examples to it and figured out my own method of range specification.

Cheers ! :D
SignatureEnergy can neither be created nor destroyed; only transformed.
 
http://www.whisperwillow.com
Advertising Bot
Posted on 18-05-2012 08:48
Bot Agent

Posts: n^x
Joined: Always

  
slaughter
Only btw:
If your infusion is for PHP-F 7.01.xx and/or PiF, you can use the profile_link() function for the link to the user's profile.
 
Grimloch
OK. It's done! New panel mod posted under Modifications forum.

Cool
SignatureEnergy can neither be created nor destroyed; only transformed.
 
http://www.whisperwillow.com
Jump to Forum:
Similar Threads
Thread Forum Replies Last Post
Paths in administration panel Feature Requests 6 13-03-2012 03:40
Forum Threads List Panel (v0.08.01) Suspected Bugs and Errors 10 04-03-2012 03:50
Latest Threads Panel Suspected Bugs and Errors 2 02-03-2012 04:07
Forum threads list panel Suspected Bugs and Errors 8 01-03-2012 04:04
Radio Panel General Questions 3 01-03-2012 04:00
Share this thread
URL:
BB-Code:
HTML:
AddThis:
Share |
Render time: 0.12 seconds - 96 Queries 989,157 unique visits