Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2005, 06:00 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default seeing how long session has been active?

ok, its me again!

Ive set a session variable called '$_SESSION['subject']' which is alive all the time a user is on a certain subject page.

I need to know how long this session is alive for, so i can judge how long someone is on this subject page for.

how can i view the length of time the session has been set?

does that make sense?

cheers
Ash

My new web design domain
www.askmultimedia.co.uk
__________________
My new web design domain
www.askmultimedia.co.uk
 
Old April 19th, 2005, 06:10 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

ok, ive found that you can view the timestamp of a session using this:-

$start = time('subject');

which will set the variable $start to the initial timestamp.

What i need now is to kno how to manipulate these timestamps, into a real time value such as 1minute 34seconds!

ill have a go, but anything in the mean time will be a big help!
cheers
ash


My new web design domain
www.askmultimedia.co.uk
 
Old April 19th, 2005, 10:17 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try something like this

Code:
function elapsed_time($timestring)
{
  //Get the time difference.
  $x = split(",", date("Y,m,d,H,i,s", time() - strtotime($timestring)));

  //Return an associative array.  Subtract 01.01.1970 because
  //time() and strtotime() return time values WRT the Unix Epoch.
  return array("years" => $x[0] - 1970,
               "months" => $x[1] - 1,
               "days" => $x[2] - 1,
               "hours" => $x[3],
               "minutes" => $x[4],
               "seconds" => $x[5]);
}
Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 19th, 2005, 10:25 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

hey, ive done it now, just compared the timestamps and calculated the difference, it works, so im happy!lol


another little problem ive got,(sorry!) i want to select all items from a record in a MySQL db which = 0.

so say there is a record with 20 1's or 0's in.

I want to select all the zeros!

how would i do this?

cheers
Ash

My new web design domain
www.askmultimedia.co.uk
 
Old April 19th, 2005, 10:28 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use a where clause in your sql statment.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 19th, 2005, 10:42 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

would it be like

SELECT * FROM questions WHERE value = '0'?

would this return all fields that contain a zero? like i said, there are 20 fields in the table and i only want the ones with 0 in them!

cheers
Ash



My new web design domain
www.askmultimedia.co.uk
 
Old April 19th, 2005, 01:05 PM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

more complicated then that. You have to use the field names. Is is also not a good practice to use SELECT *. What you can do is have all the field names in an array then use a foreach statment for the select and the while clause and appending to the sql statment. WHERE clasuses are formated in "WHERE `Field_Name` = 0 OR `Field_Name_2` = 0 AND `Field_Name_3` != 1"

Now that what I read more into what you are doing, where clauses are for returning only specified rows. Not fields within the rows. Sounds like you want to only collect the zero value fields within the same row. Is that correct? If so I would suggest pulling all fields that you want to check aggenst and check them for zero in the result with php. The best way to do that really depends on what you are doing with the values. No matter how you are doing it the value is always going to be zero.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent





Similar Threads
Thread Thread Starter Forum Replies Last Post
Long Long int to bin walid C# 0 January 23rd, 2007 12:47 PM
Remote session active??? jaywhy13 Classic ASP Basics 2 January 30th, 2005 02:25 AM
Use of long long int jvanp C++ Programming 7 October 3rd, 2004 01:59 PM
string to "long long" without using atoll sarraju C++ Programming 2 August 4th, 2004 07:19 AM
Modifying long text in a long field sajsal Classic ASP Databases 1 February 20th, 2004 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.