$row and other questions...


#1

ok so here is my code
[php]<?php
include “settings.php”;
$command = isset($_REQUEST[‘command’]) ? $_REQUEST[‘command’] : null;
$id = isset($_GET[‘id’]) ? $_GET[‘id’] : null;
$type = isset($_GET[‘type’]) ? $_GET[‘type’] : null;

	$query = mysql_query("SELECT * FROM vircom ORDER BY lastUpdate DESC");
		while ($row = mysql_fetch_array($query))
		echo "

OS: Computer Name: Ram: Last seen online:
$row[operatingSystem] $row[compName] $row[ramMemory]Mb $row[lastUpdate]
"; [/php] the part [php]$row[lastUpdate][/php] shows time in sql standard format and I want to substract this this time from current time and if difference is more than 1 i would like it to show its online.... could someone show me code that could do this??

#2

Well, Skill, Are you talking about the — $row[lastUpdate] — ??? Is that the date you are talking about?
And, how do you store it in the database? Standard “datetime” format? If you are talking about subtracting
one from the time, I will assume you mean 1 hour? To get the hour you can format it with one of the time
functions in PHP. Like day, hour, etc… And, once you get the hour, you can just subtract one.

So, here are a couple of date/time functions that are easy to use…

// Prints something like: Monday
echo date(“l”);

// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date(‘l jS \of F Y h:i:s A’);

// prints something like: Wednesday the 15th
echo date(‘l \t\h\e jS’);

Here is how to add an hour to the current time…
[php]

<?php $todayDate = date("Y-m-d g:i a");// current date $currentTime = time($todayDate); //Change date into time (in seconds) $timeAfterOneHour = $currentTime+60*60; echo "
Current Date and Time: ".date("Y-m-d H:i:s",$currentTime); echo "
Date and Time After adding one hour: ".date("Y-m-d H:i:s",$timeAfterOneHour); ?>

[/php]

Hope that is what you are looking for… Good luck…


#3

[php]when I use it like this $currentTime = time($row[lastUpdate])
$query = mysql_query(“SELECT * FROM vircom ORDER BY lastUpdate DESC”);
while ($row = mysql_fetch_array($query))
echo "


OS: Computer Name: Ram: Last seen online:
$row[operatingSystem] $row[compName] $row[ramMemory]Mb $currentTime
"; [/php] I get error [code]Parse error: syntax error, unexpected T_VARIABLE in C:\wamp12\www\index.php on line 22[/code] 22 is the line where I declared currentTime what could be the problem??

#4

First, you didn’t tell me if you have the “lastUpdate” defined as TimeDate in the database. Let me know.

Next, I always use quotes in row data… $row[lastUpdate] is not good, $row[‘lastUpdate’] is. I am not sure
if this is really a problem. I have just found that it will sometimes take the variable inside it as a number instead
of the actual text name it is supposed to be.

Now, why the error… You showed me that you set the time BEFORE doing the query… A big No-No!
Change it to this:
[php]
$query = mysql_query(“SELECT * FROM vircom ORDER BY lastUpdate DESC”);
while ($row = mysql_fetch_array($query))
$currentTime = time($row[lastUpdate]); //Get time of EACH row…
echo "
[/php]

Hope that helps…


#5

yes its in DateTime
and after using your code I get the error like this

Notice: Use of undefined constant lastUpdate - assumed 'lastUpdate' in C:\wamp12\www\index.php on line 21

#6

Ah, Skill, what is line 21???


#7

Nevermind I have solved it, thank you for all your help.


#8

Nevermind doesn’t help anyone else get it running on their projects! In a forum that is helping you solve your problems, it is kind if you post the solution or at least explain how you solved it for others.

But, you are welcome, come back again with the next problem…