FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Seconds to Minutes





DanielXP
Seconds to minutes + seconds

I have a time stored in my database and it tell how long you have to wait until you can do it again.

i have this code
Code:
<script>
<!--
function ctime(secs)
   if secs > 59 then
      myMinutes = Math.Floor(secs/60);
      mySeconds = secs-(Math.Floor(secs/60)*60);
         if mySeconds < 10 then
            mySeconds = "0"..mySeconds;
         end
      myTime = myMinutes..":"..mySeconds;
   else
         if secs < 10 then
            mySeconds = "0"..secs;
         end
      myTime = "0:"..mySeconds;
   end 
   return timeleft;
end
//-->
</script>


In my funtions.php page

in my other page i have included the funtions file and added this

Code:
$timeleft = ctime($timeleft);
echo "<input type='submit' value='$timeleft' disabled='disabled'>";


I keep getting this error

Fatal error: Call to undefined function: ctime() in /home/gm/public_html/www/cartheft.php on line 62

I can't make it out becoz the funtion is included.

If you could please help thanks.
Magicman
Are you sure you called that function into the other page properly? Do other functions defined in functions.php work? I'm not a php expert but I know a little so this is all the help I can give.
DanielXP
Yes
Yes
OK thanks any way

I don't know if PHP and Javascript go
Mgccl
that's Javascript...
how can you call Javascript function in PHP...
come on... you are better than that...
write a function in PHP for it
Magicman
Wow, I wasn't even paying attention to that. Yeah you need to define the function in the same language or else it wont work. Javascript and PHP are not the same thing so functions will not work between them.
kv
Magicman wrote:
Wow, I wasn't even paying attention to that. Yeah you need to define the function in the same language or else it wont work. Javascript and PHP are not the same thing so functions will not work between them.


It won't work. But not because they are in different languages, but because they are executed on different machines! Yes, javascript is executed on client and php is executed on server.

There are languages which are compatible with each other and can be called from one onother (probably using a wrapper).
DanielXP
I wouldn't know how to make it in PHP

how would i be able to do the
Code:
$timeleft = ctime($timeleft);


in javascript?
hexkid
DanielXP wrote:
I wouldn't know how to make it in PHP

how would i be able to do the
Code:
$timeleft = ctime($timeleft);


in javascript?


Wrong forum. But isn't your original post already JavaScript? ?!?!?!?

Also, ctime() isn't a PHP function.
You might want to properly define your function requirements when you post to the right forum; saying "I want to implement PHP's ctime() function in JavaScript" will not get you the answers you look forward to get.
DanielXP
I have made this funtion

Code:
function timeleft($timeleft){
if($timeleft > 59)
{
$minutes = round($timeleft / 60); //works out how many minutes there are and rounds them
$minseconds = $minutes * 60; //works out how many seconds used in them minutes
$seconds = $timeleft - $minseconds; //takes the timeleft away from the seconds used in the minutes
$timeleft = "$minutes Minutes $seconds Seconds";
}
else
{
$timeleft = "$timeleft Seconds";
}
return $timeleft;
}


It works most of the time but then i turns to "5 Minutes -4 Seconds"

Its driving me crazy.
hexkid
DanielXP wrote:
Its driving me crazy.


Try floor() instead of round().

Code:

round(296 / 60) == round(4.933333333) == 5
5 * 60 == 300
296 - 300 == -4
==============================
floor(296 / 60) == floor(4.933333333) == 4
4 * 60 == 240
296 - 240 == 56
DanielXP
YIPPY thanks sooooo much

Prop think im a n00b but o well

can't be good at every thing

not found what that thing is yet but o well

Solved Cool
Related topics
[CLIP]Incredible driving skill!!!
Pepperpot Hot
Clock-javascript
auto refresh
Why are we not allowed to put in affiliate links in our sig?
video to .flv with php?
About downtime of Frihost
Time Travel: Is it Possible?
Storing minutes and seconds in a database
So, you don't believe in God, but you will die in 60 minutes
Firefox crashes after some time
If you had the power! (NSFW)
What makes the time go?
With myself
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.