Jump to content

Archived

This topic is now archived and is closed to further replies.

webdogjcn

Logged in users list for forum

Recommended Posts

[code]
$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'");
[/code]

[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_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";[/code]

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.

Share this post


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

[code]line 118: $all=implode(",", $users);[/code]

I really need help!

Share this post


Link to post
Share on other sites
you are only fetching 1 row. you need to do like, a while loop

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

Share this post


Link to post
Share on other sites
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:
[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++;
}[/code]

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?

Share this post


Link to post
Share on other sites
Firstly, just a quick tip: You don't have to put each update in a separate query, you can just do this:[code]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'");[/code]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:[code]$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 />';
}
}[/code]Let me know if that fixes your problem.

Share this post


Link to post
Share on other sites

×

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.