Jump to content


Photo

Logged in users list for forum


  • Please log in to reply
5 replies to this topic

#1 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 June 2006 - 07:00 PM

 $year = date(Y);
 $month = date(m);
 $day = date(d);
 $hour = date(H);
 $minute = date(i);

// Do this everythime I view a page in the forum
 mysql_query("UPDATE user_info SET log_year='$year' WHERE user_name='$user'");
 mysql_query("UPDATE user_info SET log_month='$month' WHERE user_name='$user'");
 mysql_query("UPDATE user_info SET log_day='$day' WHERE user_name='$user'");
 mysql_query("UPDATE user_info SET log_hour='$hour' WHERE user_name='$user'");
 mysql_query("UPDATE user_info SET log_minute='$minute' WHERE user_name='$user'");

 $minute_other= ($minute - 16);
 $minute++;
 $query=mysql_query("SELECT user_name FROM user_info WHERE log_year='$year' AND log_month='$month' AND log_day='$day' AND log_minute BETWEEN '$minute_other' AND '$minute'");
 if (!$query){
 echo"mysql_error()";
 }
 echo"username: $user and minutes: $minute and $minute_other<br>";
 $users=mysql_fetch_array($query);
 $all=implode(",", $users);
 echo"$all";

Okay I have tried logging in as three different users but only the first one is listed and it gets listed twice. I have displayed the values of the different users login times and compaired them and they fit within the range defined in the BETWEEN statement.

#2 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 June 2006 - 07:24 PM

Now I am just getting:
Warning: implode(): Bad arguments. in /home/www/altgames.awardspace.com/members/forums/index.htm on line 118

line 118: $all=implode(",", $users);

I really need help!

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 07:30 PM

you are only fetching 1 row. you need to do like, a while loop

echo "online users: ";
while( $users=mysql_fetch_array($query)) {
 echo $users['user_name']. " ";
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 08 June 2006 - 10:58 PM

Okay I did that and I noticed I wasn't adding in the hour to the query which caused some wierd problems. However, now it just displays nothing with the error:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource

Which obviously means that nothing is being returned by the query

Here is the current code:
$minute_other= ($minute - 16);
$minute++;
$query=mysql_query("SELECT user_name FROM user_info WHERE log_year='$year' AND log_month='$month' AND log_day='$day' AND $log_hour='$hour' AND log_minute BETWEEN '$minute_other' AND '$minute'");
$online=mysql_numrows($query);

$i = 0;
while($i < $online) {
$users = mysql_result($query,$i,'user_name');
echo $users['user_name']. " ";
$i++;
}

It should work b/c what is set as the users log time is this:
+-Year----Month----Day----Hour----Minute----+
+--2006----06--------08------17--------55-------+

And the current timestamp is
+--2006----06--------08------17--------56-------+

So why is it not working?

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 08 June 2006 - 11:22 PM

Firstly, just a quick tip: You don't have to put each update in a separate query, you can just do this:
mysql_query("UPDATE `user_info` SET `log_year`='$year', `log_month`='$month', `log_day`='$day', `log_hour`='$hour', `log_minute`='$minute' WHERE `user_name`='$user'");
As for your actual problem, I'm assuming user_name is unique? In which case you don't need to use SQL to do your validation and can just use:
$minute_other = $minute - 16;
$minute++
$query = mysql_query("SELECT * FROM `user_info`");
while($info = mysql_fetch_array($query))
{
if($info['log_year'] == $year && $info['log_month'] == $month && $info['log_day'] == $day && $info['log_hour'] == $hour && $info['log_minute'] >= $minute_other && $info['log_minute'] <= $minute)
{
echo $info['user_name'] . '<br />';
}
}
Let me know if that fixes your problem.
[table]



Don't worry, the printer fairies will sort it out.

#6 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 09 June 2006 - 12:01 AM

Yea, nevermind I figured it out...thanks everyone for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users