473,797 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to ad a online table, what should it be set to?

117 New Member
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($sq l ,$db);[/PHP]

And call it:
[PHP]<?php printf($online) ; ?>[/PHP]

is there a special way to count the value of Y and skip N
Aug 29 '07 #1
21 1803
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!
Aug 29 '07 #2
Breana
117 New Member
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';
Aug 29 '07 #3
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.
Aug 29 '07 #4
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).
Aug 29 '07 #5
Breana
117 New Member
I did that, i updated my first post.
But i cant call it, it just shows y
Aug 29 '07 #6
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:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE
  2.         `users`
  3.     ADD
  4.         `last_active`
  5.             TIMESTAMP
  6.             NOT NULL
  7.             DEFAULT CURRENT_TIMESTAMP
  8.             ON UPDATE CURRENT_TIMESTAMP,
  9.     ADD
  10.         KEY
  11.             (`last_active`);
  12.  
Then, set and enforce your default timeout, and if the User's session is still valid, 'touch' his `last_active` value:
Expand|Select|Wrap|Line Numbers
  1. // Check to see if User's session has timed out.
  2. $_sql = "
  3. SELECT
  4.         `last_active`
  5.     FROM
  6.         `users`
  7.     WHERE
  8.         `user_id` = '{$user_id}'
  9.     LIMIT 1";
  10. $_res = mysql_query($_sql);
  11. $_row = mysql_fetch_row($_res);  //  $_row[0] is `last_active`.
  12. mysql_free_result($_res);
  13.  
  14. // Set timeout to 15 minutes
  15. define('TIMEOUT', 900);
  16. if( strtotime($_row[0]) < (time() - TIMEOUT) )
  17. {
  18.     // User is no longer logged in; his session has timed out
  19. }
  20. else
  21. {
  22.         // User is logged in; set his `last_active` to CURRENT_TIMESTAMP.
  23.     $_sql = "
  24. UPDATE
  25.         `users`
  26.     SET
  27.         `last_active` = NOW()
  28.     WHERE
  29.         `user_id` = '{$user_id}'
  30.     LIMIT 1";
  31.     mysql_query($_sql);
  32. }
  33.  
Then, to find the number of Users that are online (active within the last 15 minutes):
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         COUNT(`user_id`)
  3.     FROM
  4.         `users`
  5.     WHERE
  6.         `last_active` > TIMESTAMP(NOW(), '00:15:00')
  7.     GROUP BY
  8.         `user_id`
  9.  
Aug 29 '07 #7
Breana
117 New Member
Ok, seems complex but how do i set there "CURRENT_TIMEST AMP" in the login or is it auto done?
Aug 29 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, Breana.

CURRENT_TIMESTA MP 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!
Aug 29 '07 #9
Breana
117 New Member
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?
Aug 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
7817
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 table) in a loop with the following statement: reorg table xxx.yyy inplace allow write access.
16
5471
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 - and can get runstats to be online but reorg only offers offline at the activities settings. I have tried to understand why - I thought that online was always offered ? I think that all my indexes are type 2 - I ran some reorg indexes all on the...
12
3100
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 asp editing (like I used to be able to do with 2K/IIS5) where I use VS.NET, open an asp file, make changes, save and refresh my browser. Problem is that I get an Access is Denied error when I try to save the file and then the file gets wiped on...
3
1840
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 tables (editing). So, 'change table A' can be work for hours. There are tables tableA and tableB. Changes are made by thin client. If you change tableA, you have to also change tableB to 'finish' operation. Between starting changing tableA...
5
3648
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
9
2936
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 return the matching record however the second query needs to find a random record and return it. The union is causing me some trouble. It seems that any method i try to find a random record just causes an error. Here is an example of a query...
4
1175
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 to change the background color on a table called "table1" Table1.BackColor = Drawing.Color.Blue
1
2045
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', b'03' '33', 'c01' to '33', 'c40' : total 40 entries
6
7721
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 db BPEDB online to / var/tmp During the backup the application hangs on just one table
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10469
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7560
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5459
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4135
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 we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.