Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dynamitemedia
Binge Watcher

any PHP experts here? need some help

i am having a huge problem trying to get this loop done

i have a loop and because its not using php time or date i am having a horrible time trying to make it update the minutes and start the seconds back to 0 as you see below it will show one minute but then its back to :70 etc

its just keeps doing this:

time is 00:00:00 
time is 00:00:10
time is 00:00:20
time is 00:00:30
time is 00:00:40
time is 00:00:50
time is 00:1:00 <---another issue
time is 00:00:70
time is 00:00:80
time is 00:00:90


i dont need to echo each time this is just an example, i am just trying to get it to keep going up.

anyone here have any ideas, would greatly appreciate a little help on this. been scouring the net and no luck yet
Twitter: iptvmyway facebook: iptvmyay
Channels: Warriors of War, Go Fight Live, Heading Outdoorz, IPTVmyway
0 Kudos
10 REPLIES 10
scrager
Visitor

Re: any PHP experts here? need some help

If you want proper help, you should post your php code.

it looks like you are not keeping track of your minutes and not resetting your seconds. Or your seconds->hours/minutes/seconds routine does not work properly.

To handle the left padding of minutes, you should try

printf("%02d",$minutes)
0 Kudos
dynamitemedia
Binge Watcher

Re: any PHP experts here? need some help

sorry should have added it your right

i=1;

while($i<=$ts) {
$num = '000';
$sequence = $num + $i;

if ($sequence == "1") {
$ss = "00:00:00";

echo " time is $ss";

} else {

$one = "1"; // need to take away from sequence used above

$minutez= "00";
$secondz= "00";
$hourz = "00";

$seq = $sequence-$one;
$ten ="10";
$seq = $seq*$ten;
$zeros ="00";

$secondz = $zeros + $seq;

if ($secondz == "60"){

$secondz=$zeros;

if ($minutez < 10){

$minz = "0$minutez";
} else{
$minz = "$minutez";
}
$minutez = $minz + $one;

}


$ss = "$hourz:$minutez:$secondz";

echo "time is $ss<br />";

} // closes if statement

$i++;


} // closes while loop
Twitter: iptvmyway facebook: iptvmyay
Channels: Warriors of War, Go Fight Live, Heading Outdoorz, IPTVmyway
0 Kudos
scrager
Visitor

Re: any PHP experts here? need some help

Ok, I'm not exactly sure what you're trying to do since there is no reference to any actual time constraints, but this should help you replace that chunk of code:


function secondsToTime($seconds) {
$s = $seconds%60;
$m = floor($seconds/60)%60;
$h = floor($seconds/60/60);
return sprintf("%02d:%02d:%02d",$h,$m,$s);
}

for($seconds=0;$seconds<=500;$seconds+=10) {
echo secondsToTime($seconds)."<br>";
}
0 Kudos
dynamitemedia
Binge Watcher

Re: any PHP experts here? need some help

thanks one thing i need to figure out is how to use functions better....

I just got it working another way actually . but gonna test your way as well...

here is what i did:
$i=1;

while($i<=$ts) {
$num = '000';
$sequence = $num + $i;

if ($sequence == "1") {
$ss = "00:00:00";

echo "time is $ss <br />";

} else {

$one = "1"; // need to take away from sequence used above

$seq = $sequence-$one;
$ten ="10";
$seq = $seq*$ten;


// get duration and start time
$hourz = intval(intval($seq) / 3600);
if ($hourz < 10){
$hr = "0$hourz";
} else {
$hr = "$hourz";
}

$minutez = intval(((intval($seq) / 60) % 60));
if ($minutez < 10){
$minz = "0$minutez";
} else{
$minz = "$minutez";
}
$secondz = intval(intval(($seq % 60)));
if ($secondz < 10){
$secz = "0$secondz";
} else {
$secz = "$secondz";
}

$ss = "$hr:$minz:$secz";
echo "time is $ss <br />";




do you see a neater way of this working? maybe less code? this is the outcome also so i know its working



time is 00:00:00
time is 00:00:10
time is 00:00:20
time is 00:00:30
time is 00:00:40
time is 00:00:50
time is 00:01:00
time is 00:01:10
time is 00:01:20
Twitter: iptvmyway facebook: iptvmyay
Channels: Warriors of War, Go Fight Live, Heading Outdoorz, IPTVmyway
0 Kudos
scrager
Visitor

Re: any PHP experts here? need some help

1. I think your code complications comes in your misunderstanding of loops and also of type conversion.
PHP does auto type conversion, so if you have $a="000" and $i=1, then $a+$i is equal to 1 because the + converts both to numerics then adds them.

2. Your first if statement inside the while loop is pointless
instead of:

while($i<=$ts) {
$sequence = $i;

if ($sequence == "1") {
$ss = "00:00:00";

echo "time is $ss <br />";

} else {

$one = "1"; // need to take away from sequence used above

$seq = $sequence-$one;
...


why not subtract one first, then calculate, then echo once at the end. when $i=1, then $sequence will be 0 and your output will still be "00:00:00"

while($i<=$ts) {
$sequence = $i - 1; //take away one

...


more in next post.
0 Kudos
scrager
Visitor

Re: any PHP experts here? need some help


$hourz = intval(intval($seq) / 3600);
$minutez = intval(((intval($seq) / 60) % 60));
$secondz = intval(intval(($seq % 60)));


those three lines are equivalent to


$s = $seconds%60;
$m = floor($seconds/60)%60;
$h = floor($seconds/60/60);


you don't need to intval($seq) cause $seq is already an integer. intval and floor basically do the same thing.


your if blocks to add the leading zero are basically correct, but you don't need the else statement. You could just add the leading 0 to the variable itself instead of assigning to a new variable.

Here is your code cleaned up:

$i=1;

while($i<=$ts) {
$sequence = $i;

$seq = $sequence-1; //need to remove 1 from your comments
$seq = $seq*10;


// get duration and start time
$hourz = intval($seq / 3600);
if ($hourz < 10){
$hourz = "0$hourz";
}

$minutez = intval($seq / 60) % 60;
if ($minutez < 10){
$minutez = "0$minutez";
}

$secondz = $seq%60;
if ($secondz < 10){
$secondz = "0$secondz";
}

$ss = "$hourz:$minutez :$secondz ";
echo "time is $ss <br />";
}
0 Kudos
scrager
Visitor

Re: any PHP experts here? need some help

also, this:

$hourz = intval($seq / 3600);
if ($hourz < 10){
$hourz = "0$hourz";
}

$minutez = intval($seq / 60) % 60;
if ($minutez < 10){
$minutez = "0$minutez";
}

$secondz = $seq%60;
if ($secondz < 10){
$secondz = "0$secondz";
}

$ss = "$hourz:$minutez :$secondz ";


is equivalent to this:

$s = $seconds%60;
$m = floor($seconds/60)%60;
$h = floor($seconds/60/60);
$ss = sprintf("%02d:%02d:%02d",$h,$m,$s);


I just put mine in a function so that it can be reused.
0 Kudos
kbenson
Visitor

Re: any PHP experts here? need some help

I think it's worth noting that it seems a good bit of the problems arise from you trying to display a duration as an instant. This can be confusing. When presented with 14:13:28, I don't immediately think something has been going on for 14 hours, 13 minutes and 28 seconds, I think 2:13:28 PM of the current day. I think that's why PHP doesn't have a built-in easy way to format in that manner. The date() function will easily format an epoch time, but using it's formatting for a duration leads to easy to misunderstand output.

Something like "1d 13h 6m 28s" is just as (if not more) obvious as a duration, and you don't need special formatting to display

$s = $interval % 60;
$m = ($interval / 60) % 60;
$h = ($interval / 60 / 60) % 24;
$d = ($interval / 60 / 60 / 24);
print "{$d}d {$h}h {$m}m {$s}s\n";


If you aren't interested in changing the display format, then just ignore this.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
dynamitemedia
Binge Watcher

Re: any PHP experts here? need some help

thanks for the help all is working right now, i am still trying to work it to use your function but tht has always confused me for some reason same for loops.

will play with it later today.

I found it wasn't even necessary to do it this way but its OK I learned something!!
Twitter: iptvmyway facebook: iptvmyay
Channels: Warriors of War, Go Fight Live, Heading Outdoorz, IPTVmyway
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.