Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/
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?
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.
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.