Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

how difference between time

Codes here !

Moderators: macek, egami, gesf

how difference between time

Postby pucca » Fri Jul 05, 2013 6:58 pm

i have a tabel as follow as:
Code: Select all
username   | time         
-----------|---------------
aq         |   05:55:07         
aq         |   05:55:09   
megi       |   05:55:37   
megi       |   05:55:40         
megi       |   05:55:45 


i have a script can difference between time as follow as:
Code: Select all
SET @waktu= null;
    SELECT username, tanggal, module, action, pagename,
      IFNULL(timediff(`waktu`,@waktu), 0) as selisih_waktu, @waktu := `waktu` as time
    FROM mdl_temporer_log2 WHERE rolename = 'Student'
    ORDER BY waktu;


But that script will show a tabel:
Code: Select all
 username   | selisih_waktu |   time         
    -----------|---------------|--------------
    aq         |     0         |     05:55:07         
    aq         |  00:00:02     |     05:55:09   
    megi       |   00:00:18    |     05:55:37   
    megi       |  00:00:03     |     05:55:40         
    megi       |  00:00:03     |     05:55:45


But i want show that output as follow as:

Code: Select all
    username   | selisih_waktu |   time         
    -----------|---------------|--------------
    aq         |     0         |     05:55:07         
    aq         |  00:00:02     |     05:55:09   
    megi       |   0           |     05:55:37   
    megi       |  00:00:03     |     05:55:40         
    megi       |  00:00:03     |     05:55:45   


how that script will show that output table? :)
pucca
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Jun 27, 2013 5:35 pm

Re: how difference between time

Postby johnj » Fri Jul 05, 2013 8:23 pm

Sorry, not able to make out what you are trying to achieve.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how difference between time

Postby pucca » Sat Jul 06, 2013 5:53 pm

so, how to overcome these problems? or is there another solution to resolve it with the sql scripts or php? because I'm really confused
pucca
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Jun 27, 2013 5:35 pm

Re: how difference between time

Postby johnj » Mon Jul 08, 2013 3:09 am

What is the problem that you are facing?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how difference between time

Postby pucca » Thu Jul 11, 2013 5:46 pm

I can not reduce the time and based on each row display the username as follows:

Code: Select all
username   | difference_time |   time         
    -----------|---------------|--------------
    aq         |     0         |     05:55:07         
    aq         |  00:00:02     |     05:55:09   
    megi       |   null           |     05:55:37   
    megi       |  00:00:03     |     05:55:40         
    megi       |  00:00:03     |     05:55:45


I am confused to use php scripts or mysql script that generate output that table, please help me because The problem is the task of my thesis and I have to present it!
pucca
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Jun 27, 2013 5:35 pm

Re: how difference between time

Postby johnj » Thu Jul 11, 2013 11:03 pm

All you have to do is whenever there is a new username or change in username reset the time calculation.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how difference between time

Postby pucca » Fri Jul 12, 2013 7:03 pm

I've tried to make the sql script to create a procedure, in mysql with input parameters and invoked only when using
Code: Select all
call selisih ('Megi')
, and I get confused when they want to call another username in php, so when displaying the username table together, what's the solution? :help:
pucca
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Jun 27, 2013 5:35 pm

Re: how difference between time

Postby johnj » Sat Jul 13, 2013 6:17 am

whenever there is a change in user name the time difference will be zero. keep that in mind and fix your script.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how difference between time

Postby pucca » Sat Jul 13, 2013 10:08 pm

how to fix the script? please help!
pucca
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Jun 27, 2013 5:35 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron