473,806 Members | 2,565 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
21 1805
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:
Expand|Select|Wrap|Line Numbers
  1.  $_sql = "
  2. UPDATE
  3.         `users`
  4.     SET
  5.         `last_active` = NOW()
  6.     WHERE
  7.         `user_id` = '{$user_id}'
  8.     LIMIT 1";
  9.  
Aug 29 '07 #11
Breana
117 New Member
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($sq l ,$db);

if ($myrow = mysql_fetch_arr ay($result)) {

do {

$uid = $myrow["userid"];
$uname = $myrow["login"];

} while ($myrow = mysql_fetch_arr ay($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=\"im ages/b_m.gif\">Welco me <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.ph p\">CONTINUE >></a><br /><br /><p align=\"center\ "><img src=\"images/Welcome_Back.gi f\" 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.ph p>Create A New Account!</a>";


}

session_registe r("loggedin") ;
session_registe r("upwd");
session_registe r("uid");
session_registe r("uname");

?>[/PHP]
Aug 29 '07 #12
pbmods
5,821 Recognized Expert Expert
Heya, Breana.

Make sure that the `last_active` field is a TIMESTAMP with DEFAULT CURRENT_TIMESTA MP and ON UPDATE CURRENT_TIMESTA MP.

Also note this line:
Expand|Select|Wrap|Line Numbers
  1.  $sql = "UPDATE `users` SET `last_active` = NOW() WHERE `user_id` = '{$user_id}' LIMIT 1";
  2.  
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:
Expand|Select|Wrap|Line Numbers
  1.  $sql = "UPDATE `users` SET `last_active` = NOW() WHERE `userid` = '{$uid}' LIMIT 1";
  2.  
Aug 29 '07 #13
Breana
117 New Member
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]
Aug 29 '07 #14
pbmods
5,821 Recognized Expert Expert
Heya, Breana.

You're setting the value of $_sql, but you never call mysql_query().. ..
Aug 29 '07 #15
Breana
117 New Member
Ok like this:
[PHP]<?
$sql = "SELECT COUNT(`uid`) FROM `users` WHERE `last_active` > TIMESTAMP(NOW() , '00:15:00')
GROUP BY `uid`";
$result = mysql_query($sq l ,$db);?>[/PHP]
Aug 29 '07 #16
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.
Aug 29 '07 #17
Breana
117 New Member
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($sq l ,$db);
mysql_fetch_row ($result);?>[/PHP]

"echo index 0" what....
you mean i need to echo ("index 0"); or what?
Aug 29 '07 #18
pbmods
5,821 Recognized Expert Expert
Heya, Breana.

This line:
Expand|Select|Wrap|Line Numbers
  1. mysql_fetch_row($result);
  2.  
Returns an array. You'll want to assign that array to a variable and then echo its 0th index.

I.e.,
Expand|Select|Wrap|Line Numbers
  1. $row = mysql_fetch_row($result);
  2. echo $row[0];
  3.  
Aug 29 '07 #19
Breana
117 New Member
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
Aug 29 '07 #20

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

Similar topics

9
7818
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
5472
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
3105
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
1843
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
3651
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
2937
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
1178
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
7723
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
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10372
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
10110
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
9187
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...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
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
4329
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
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.