Ok, i am adding a table to the users table called online.
So when they login it will set (online) to Y and when they logout it will be set to N.
But what should it be created as, it will be updated often and i need to beable to read it from my php in the Members online section?
varchar(50), int(10), or Text...
And how do i call the results of it not in text Y but in total.
Like lets say there is a total 50 users=Y so it will PRINT 50.
I have tried several times but i keep getting eather 9empty) or (Y) Not the total as 8
I created the table like this:
[PHP]ALTER TABLE users
ADD online varchar(1) default 'N';[/PHP]
And call it like this:
[PHP]$sql="SELECT online FROM users WHERE online = $Y";
$result = mysql_query($sql ,$db);[/PHP]
And call it:
[PHP]<?php printf($online); ?>[/PHP]
is there a special way to count the value of Y and skip N
21 1762 ak1dnar 1,584
Recognized Expert Top Contributor
Ok, i am adding a table to the users table called online.
So when they login it will set (online) to Y and when they logout it will be set to N.
But what should it be created as, it will be updated often and i need to beable to read it from my php in the Members online section?
varchar(50), int(10), or Text...
Still I am struggling to understand your question Breana. could you please explain it little bit clearly. Thanks!
Ok, i am doing this.
ALTER TABLE users
ADD online (.........) ;
But what do i set it to?
Text, INT(10) , VARCHAR (50) or else?
I need to be able to read from it and update it easly.
Default has to be 'n'
So i tried this:
ALTER TABLE users
ADD online char(1) default 'n';
ak1dnar 1,584
Recognized Expert Top Contributor
And how do i call the results of it not in text Y but in total.
Like lets say there is a total 50 users=Y so it will PRINT 50.
I have tried several times but i keep getting Y,Y,Y,Y,Y,Y,Y,Y Not the total as 8
Now you have edited the original post with more details, but yet it doesn't describe the problem. Sorry...Could you please show us the NOT working code snippets. then it might be easier to get through it.
ak1dnar 1,584
Recognized Expert Top Contributor
Ok, i am doing this.
ALTER TABLE users
ADD online (.........) ;
But what do i set it to?
Text, INT(10) , VARCHAR (50) or else?
I need to be able to read from it and update it easly.
Default has to be 'n'
So i tried this:
ALTER TABLE users
ADD online char(1) default 'n';
Create a separate column (Say Status) on the users table where you have stored those login details. and set the default value to the column as 'N'.
Then when users logs in to the system UPDATE the records with Setting up the online status with 'Y'.
data type for the Status column should be varchar(1).
I did that, i updated my first post.
But i cant call it, it just shows y
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
Here's an idea which will let you see what Users are logged in and simultaneously enforce page timeout.
Instead of 'Y/N', use a timestamp: -
ALTER TABLE
-
`users`
-
ADD
-
`last_active`
-
TIMESTAMP
-
NOT NULL
-
DEFAULT CURRENT_TIMESTAMP
-
ON UPDATE CURRENT_TIMESTAMP,
-
ADD
-
KEY
-
(`last_active`);
-
Then, set and enforce your default timeout, and if the User's session is still valid, 'touch' his `last_active` value: -
// Check to see if User's session has timed out.
-
$_sql = "
-
SELECT
-
`last_active`
-
FROM
-
`users`
-
WHERE
-
`user_id` = '{$user_id}'
-
LIMIT 1";
-
$_res = mysql_query($_sql);
-
$_row = mysql_fetch_row($_res); // $_row[0] is `last_active`.
-
mysql_free_result($_res);
-
-
// Set timeout to 15 minutes
-
define('TIMEOUT', 900);
-
if( strtotime($_row[0]) < (time() - TIMEOUT) )
-
{
-
// User is no longer logged in; his session has timed out
-
}
-
else
-
{
-
// User is logged in; set his `last_active` to CURRENT_TIMESTAMP.
-
$_sql = "
-
UPDATE
-
`users`
-
SET
-
`last_active` = NOW()
-
WHERE
-
`user_id` = '{$user_id}'
-
LIMIT 1";
-
mysql_query($_sql);
-
}
-
Then, to find the number of Users that are online (active within the last 15 minutes): -
SELECT
-
COUNT(`user_id`)
-
FROM
-
`users`
-
WHERE
-
`last_active` > TIMESTAMP(NOW(), '00:15:00')
-
GROUP BY
-
`user_id`
-
Ok, seems complex but how do i set there "CURRENT_TIMESTAMP" in the login or is it auto done?
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
CURRENT_TIMESTAMP is an alias for NOW(). It's part of the 'magical' properties in MySQL timestamps.
It looks complex, but in reality, it's not that different than what you are doing now; instead of using 'y'/'n', you are using a number that represents the last time the User did anything.
Instead of checking to see if `online` is 'y', you are checking to see if `online` is within the last 15 minutes.
Your call. I had fun writing the timestamp solution at any rate*, so don't worry about my feelings if you want to go with the 'y'/'n' column anyway :)
*actually, you forced me to take a critical look at an odd 'feature' of my code. Right now, my session frameworks store the timeout data in the _SESSION instead of in the database. I really should be fixing this! Thanks for the inspiration!
So do i set the the table like this..
[PHP]$sql = "UPDATE last_active from users SET last_active >= ($now - $timeout)";
$result = $this->_query($sql);[/PHP]
Like that?
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
You've managed to create a UPDECT query, which is a cross between a SELECT and an UPDATE. It's not valid, but it is very creative.
The idea is that the `last_active` field stores the time of last activity; that is, the time that the User loaded the page. So you can simply set its value to the current datetime when updating it: -
$_sql = "
-
UPDATE
-
`users`
-
SET
-
`last_active` = NOW()
-
WHERE
-
`user_id` = '{$user_id}'
-
LIMIT 1";
-
I tried to but it dont change, allways 000-000-000
Iposted my code maybe i placed it wrong..
[PHP]<?php
$sql = "select * from users where login = '$login' and password = '$password'";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result)) {
do {
$uid = $myrow["userid"];
$uname = $myrow["login"];
} while ($myrow = mysql_fetch_array($result));
$loggedin = true;
$upwd = $password;
$msg = "<table width=\"500\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td><img src=\"images/top_c.gif\" width=\"500\" height=\"24\"></td>
</tr>
<tr>
<td align=\"center\" background=\"images/b_m.gif\">Welcome <font color=\"#FF0000\">$uname</font>, you are now logged in.</td>
</tr>
<tr>
<td><img src=\"images/bottom_c.gif\" width=\"500\" height=\"24\"></td>
</tr>
</table><br />
<br />
<a href=\"index.php\">CONTINUE >></a><br /><br /><p align=\"center\"><img src=\"images/Welcome_Back.gif\" width=\"300\" height=\"282\" /></p>";
$sql = "UPDATE `users` SET `last_active` = NOW() WHERE `user_id` = '{$user_id}' LIMIT 1";
} else {
$loggedin = false;
$upwd = "";
$uid = "";
$uname = "";
$msg = "<img src=\"images/invalid.gif\" width=\"402\" height=\"107\" /><br /><b><font color=\"#FF0000\">Sorry,</font></b> that login and password is not valid.<br /><br />If you have forgotten your password <a href=forgot.php>Reset Password</a>. <br />If you are a new user you will need to <a href=newuser.php>Create A New Account!</a>";
}
session_register("loggedin");
session_register("upwd");
session_register("uid");
session_register("uname");
?>[/PHP]
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
Make sure that the `last_active` field is a TIMESTAMP with DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP.
Also note this line: -
$sql = "UPDATE `users` SET `last_active` = NOW() WHERE `user_id` = '{$user_id}' LIMIT 1";
-
You'll want to replace $user_id with $uid, since that's the variable that stores the User's ID. Also, in your Users table, the User ID field is userid, not user_id. I just put some generic names in there.
Your code should look more like this: -
$sql = "UPDATE `users` SET `last_active` = NOW() WHERE `userid` = '{$uid}' LIMIT 1";
-
Oh ok, i did it now error or blank page, but on the part where i posted the whos online is empty?
I used this to call it:
[PHP]Total online: <?
$_sql = "SELECT
COUNT(`uid`)
FROM
`users`
WHERE
`last_active` > TIMESTAMP(NOW(), '00:15:00')
GROUP BY
`uid`" ?>[/PHP]
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
You're setting the value of $_sql, but you never call mysql_query()....
Ok like this:
[PHP]<?
$sql = "SELECT COUNT(`uid`) FROM `users` WHERE `last_active` > TIMESTAMP(NOW(), '00:15:00')
GROUP BY `uid`";
$result = mysql_query($sql ,$db);?>[/PHP]
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
That looks pretty good. Then just call mysql_fetch_row($result), and echo index 0 of the resulting array.
Ok i have it like this:
[PHP]Total online: <?
$sql = "SELECT COUNT(`uid`) FROM `users` WHERE `last_active` > TIMESTAMP(NOW(), '00:15:00')
GROUP BY `uid`";
$result = mysql_query($sql ,$db);
mysql_fetch_row($result);?>[/PHP]
"echo index 0" what....
you mean i need to echo ("index 0"); or what?
pbmods 5,821
Recognized Expert Expert
Heya, Breana.
This line: -
mysql_fetch_row($result);
-
Returns an array. You'll want to assign that array to a variable and then echo its 0th index.
I.e., -
$row = mysql_fetch_row($result);
-
echo $row[0];
-
Ok now it works sort of, it don't show 1 or 5 but this 209.33.95.33?
What is that... my ip address. (0 ^ 0)
Do i need to change the (0) to uid? so it shows a number
I just tried again i cant seem to get the number to pop not the ip or what ever that is...
Anyone got an idea on how to fix this?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lara |
last post by:
Hello freaks,
we have many problems with our online reorg and no idea how to resolve
it.
We had to do an online reorg beacause of 24 h online business.
We start the reorg-statements (table by...
|
by: andy.standley |
last post by:
Hi,
we are running DB2 V8.2 (8.1.0.80) on redhat linux and I am trying to
set the reorg to be online. I use the control center on the box - db2cc
and then configure automatic maintenance wizard -...
|
by: Ron Weldy |
last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net
files. On my workstation I have a share set up to the folder where the web
files reside. I am just doing quick and dirty...
|
by: Lada 'Ray' Lostak |
last post by:
Hello ppl,
Imagine some online system, based on PgSql. There are 'many' parts which
depends on each other. I will give small example, but instead of simple
table imagine changing tenths various...
|
by: snicks |
last post by:
I'm trying to exec a program external to my ASP.NET app using the following
code. The external app is a VB.NET application.
Dim sPPTOut As String
sPPTOut = MDEPDirStr + sID + ".ppt"
Dim p As...
|
by: Jeremy |
last post by:
I have a situation where i am trying to run two query's and retrieve
one record from each query, then using Union combine them into one
recordset. The First Query is strait forward and should just...
|
by: Jeff |
last post by:
I've been attempting to find the answer, but don't know what to search for.
If someone could get me started, I can figure the rest out.
I'm using visual web 2005 with vb.
The following works...
|
by: dn.perl |
last post by:
I have a table t1 with two columns : c11 varchar(32) , c22 varchar(32)
The data in the table is :
'11', 'aa01'
and on upto
'11', 'aa50' : total 50 entries
'22', 'b01'
'22', b'02'
'22',...
|
by: michael.spoden |
last post by:
Hi,
how can I fix lock-waits during an online backup? Is an online backup
in DB2 V8.2 not realy online? I'm using DB2 V8.2 Fixpak 15 on Linux.
The command to perform the backup is: db2 backup...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| | |