PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat May 28, 2005 8:37 am
If i enter into the database a value
23 and get it to show on the page i can write:
Code: Select all
<?php
echo "$data_number seconds.";
?>And that would show on the page
23 Seconds , however how do i make it so if i added a higher number like
65 , how do i make it show something like
1 minute, 5 Seconds ?
Last edited by
Dale on Sat May 28, 2005 11:53 am, edited 1 time in total.
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Sat May 28, 2005 8:45 am
well you could do some sort of see how many times 60 goes into 65 then take the remaning number and make that the seconds but why dont you just use date() and a DATE field in mysql?
R0d Longfella
Forum Newbie
Posts: 20 Joined: Fri Apr 08, 2005 7:17 am
Post
by R0d Longfella » Sat May 28, 2005 8:46 am
Code: Select all
<?php
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
?>
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Sat May 28, 2005 10:44 am
R0d Longfella wrote: Code: Select all
<?php
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
?>
Actually...
Code: Select all
printf ("%d minutes, %d Seconds", $data_number / 60, $data_number % 60);
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat May 28, 2005 10:55 am
JAM, what R0d Longfella said works fine for me. Now how would it work in the same context for doing that with hours too?
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Sat May 28, 2005 11:07 am
Code: Select all
<pre>
<?php
$data_number = 55;
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
$data_number = 65;
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
Results:
Code: Select all
55 minutes, 0 Seconds
5 minutes, 1 Seconds
See the error?
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat May 28, 2005 11:14 am
Ahh yeah i do, thats why i now want to know if adding an "hour" section in it would work just like that.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat May 28, 2005 11:39 am
C'mon man.. its not complicated, very simple math.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat May 28, 2005 11:47 am
Jcart wrote: C'mon man.. its not complicated, very simple math.
Worked it
Thanks.