Jump to content

Time Problem


Drezard

Recommended Posts

alright heres my code:

 

	$online = 1;

	$query = "SELECT * FROM user_ids WHERE online='$online'";

	$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	$count = mysql_num_rows($result);

	$timestamp = date(YmdGi);
	$old_timestamp = $timestamp - 5;

	$query = "SELECT user FROM user_ids WHERE online='$online'";

	$result_user = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	$query = "SELECT timestamp FROM user_ids WHERE online='$online'";

	$result_time = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	for ($i = 0; $i <= $count; $i++) {

		while ($row_time = mysql_fetch_array($result_time)) {

			$user_timestamp = $row_time[i];

			while ($row_user = mysql_fetch_array($result_user)) {

				$user = $row_user[i];

				if ($old_timestamp >= $user_timestamp) {

					$online = 0;

					$query = "UPDATE user_ids SET online='$online' WHERE user='$user'";

					$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

				}

			} 

		}

	}

	echo "Users online: $count";

 

Now, this is my code....

 

In the database I have something like this:

TABLE user_ids:

USER                                            TIMESTAMP                                     ONLINE
peter                                            200703071932                                       0
paul                                             200703071952                                        1
john                                              200703071532                                       0

 

Now, I want my script to go through my database (in the other parts of code it connects to the database and all of that... its just the output that i dont like)

 

Its currently 2035 where i live. Now, I want my script to search through the database for all the users that have an online status of 1... then search the database and get the timestamp... if the timestamp is greater then 5 mins old. I want the script to change the users online status to 0 (offline). So, I should get a count of all the users that have a timestamp that is newer then 5 mins. Now, what is wrong with my above script?

 

(The script is currently running on www.wintersword.com/users_online.php if you would like to see the output im getting.)

 

- Cheers, Daniel

 

Please HELP... I dont care if i have to answer a few questions, so what exactly do u want? or such...

Link to comment
https://forums.phpfreaks.com/topic/41592-time-problem/
Share on other sites

Still more problems...

 

	$timestamp = date(YmdGi);
	$old_timestamp = $timestamp - 5;

	$query = "UPDATE user_ids SET online = 0 WHERE timestamp < '$old_timestamp' AND online = 1";

	$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	$query = "SELECT * FROM user_ids WHERE online='$online'";

	$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	$count = mysql_num_rows($result);

	echo "Users online: $count";

 

is that what it should be?

Link to comment
https://forums.phpfreaks.com/topic/41592-time-problem/#findComment-201561
Share on other sites

Archived

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

×
×
  • 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.