0

I'm very new to PHP so I'm still learning how to do stuff. I cannot figure out what is wrong with this code:

if($row->played_time >= 60){
				$time = round($row->played_time,2) / 60 " mins";}
			elseif($row->played_time >= 3600){
				$time = round($row->played_time,2) / 60 / 60 " hours";}
			elseif($row->played_time >= 86400){
				$time = round($row->played_time,2) / 60 / 60 / 24 " days";}
			else{
				$time = round($row->played_time,2) " secs";
			}

The code works fine if I don't use round or include the secs, mins, hours or days but like that I get this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /usr/www/eggroup/forum/rank.php on line 37

Line 37 is the second line ($time = round($row->played_time,2) / 60 " mins";}).

How can I do what I need it to do?

Edited by Darkicon: n/a

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

This should work for you.

if($row->played_time >= 60){
				$time = round($row->played_time,2) / 60 .'  mins';}
			elseif($row->played_time >= 3600){
				$time = round($row->played_time,2) / 60 / 60 .' hours';}
			elseif($row->played_time >= 86400){
				$time = round($row->played_time,2) / 60 / 60 / 24 .' days';}
			else{
				$time = round($row->played_time,2) .' secs';
			}
0

Thanks, that worked but it seems to not be moving the decimal to only 2 places.

For example, rather than reporting "30.38 mins", it reports "30.3833333333 mins". It seems to only not move the decimal to 2 places if the decimal is repeating.

Edited by Darkicon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.