SRL Archive - General

[PHP] whats wrong with this.


XcanadamanX

2007-12-25 15:55:52

new problem explained at last post!



it worked like 10 mins ago now i changed one thing(i dont remember) and now it doesnt work.
can you guys see a problem. please excuse my crappy standards / coding. im new to php and im just fooling around with it.

[PHP]
<?
$Seconds = '3600';
$Minutes = ($Seconds / 60);
$Hours = ($Minutes / 60);
$Days = ($Hours / 24);
$Time = "$Seconds Seconds";
if ($Days >= 1){
$RHours = $Hours % ($Days);
$RMinutes = $Minutes % ($RHours);
$RSeconds = $Seconds % ($RMinutes);
$RDays = Floor($Days);
$Time = "$RDays D, $RHours Hr, $RMinutes Min, $RSeconds Sec";
}elseif ($Hours >= 1){
$RMinutes = $Minutes % ($Hours);
$RSeconds = $Seconds % ($RMinutes);
$RHours = Floor($Hours);
$Time = "$RHours Hours, $RMinutes Minutes $RSeconds Seconds";
}elseif ($Minutes >= 1){
$RSeconds = $Seconds %($Minutes);
$Minutes = Floor($Minutes);
$Time = "$Minutes Minutes, $RSeconds Seconds";
}
imagettftext($im,8.0,0,47,63,$black,$font,$Time);
imagettftext($im,8.0,0,46,61,$white,$font,$Time);
imagettftext($im,8.0,0,47,86,$black,$font,$OldB);
imagettftext($im,8.0,0,46,84,$white,$font,$OldB);
imagettftext($im,8.0,0,50,109,$black,$font,$OldC);
imagettftext($im,8.0,0,49,107,$white,$font,$OldC);
imagettftext($im,8.0,0,154,86,$black,$font,$OldE);
imagettftext($im,8.0,0,153,84,$white,$font,$OldE);
imagettftext($im,8.0,0,168,109,$black,$font,$OldLe);
imagettftext($im,8.0,0,167,107,$white,$font,$OldLe);
imagepng($im);
destroyimage($im)
?>[/PHP]

osmm

2007-12-26 21:24:19

If you have the exact same window open where you type the script use ctrl + z to undo :D. Otherwise I don't know what language that is or any others besides Pascal :p.

Jason2gs

2007-12-27 14:36:28

Checking it out…


You left out quite a few variable declarations. $im, $black, $white, $font, $OldB, $OldC, $OldE, and $OldLe.

And destroyimage doesn't seem to be a valid function.

XcanadamanX

2007-12-27 15:03:03

its actually a problem with
[php]$Time = "$Seconds Seconds";
if ($Days >= 1){
$RHours = $Hours % ($Days);
$RMinutes = $Minutes % ($RHours);
$RSeconds = $Seconds % ($RMinutes);
$RDays = Floor($Days);
$Time = "$RDays D, $RHours Hr, $RMinutes Min, $RSeconds Sec";
}elseif ($Hours >= 1){
$RMinutes = $Minutes % ($Hours);
$RSeconds = $Seconds % ($RMinutes);
$RHours = Floor($Hours);
$Time = "$RHours Hours, $RMinutes Minutes $RSeconds Seconds";
}elseif ($Minutes >= 1){
$RSeconds = $Seconds %($Minutes);
$Minutes = Floor($Minutes);
$Time = "$Minutes Minutes, $RSeconds Seconds";
} [/php]

its the elseif it has to be all the same variable its comparing. so i have figured it out. ive just encountered other problems.

ps destroyimage is fine look on php.net lol

Jason2gs

2007-12-27 17:12:59

Ah, sorry. Doesn't show up in my phpDesigner. And when I tried to compile it, it threw an error.

And is there anything more in the script? You don't have $Days, $Hours, $Minutes, or $Seconds defined here.

travo

2007-12-27 17:14:48

arent you meant to use dots in front of and behind variables in strings? like this:
[php]$Time = ".$Seconds. Seconds";

$Time = ".$RDays. D, .$RHours. Hr, .$RMinutes. Min, .$RSeconds. Sec";

$Time = ".$RHours. Hours, .$RMinutes. Minutes .$RSeconds. Seconds";

$Time = ".$Minutes. Minutes, .$RSeconds. Seconds";[/php]
etc.

[edit] i just checked some of my scripts and yeah, the dots make the variables work in the strings.

Jason2gs

2007-12-27 17:18:13

@ Travo,

It should still work without the dots.

The dots are for appending two strings together. When you use the double quotes to use a string, you'll be able to use both variables and normal text together, without problems.

Edit: Canada, mind me asking what you're trying to do here? If you want to output the current date, just use PHP's date() function.

travo

2007-12-27 17:21:00

@ jason2gs

Ok. umm…. damn this is frustrating.

i just realised you declared seconds as a string. you cant do math functions on a string.

edit: @jason2gs again. it looks like a stat sig or somethin

R0b0t1

2007-12-28 20:18:09

Oh my. Looks like CanadaMan just

EPIC FAILED!

XcanadamanX

2007-12-28 21:23:02

haha hee hee. works now. ill post the code. thats was my first…no second attempt at it php so give me a break.
@travo: actually you can do math functions on a string as php variables are variants (pretty sure, i maybe totally in left field though :rolleyes:)
yes it is a stat sig.

[php] $hours = ($minutes/60);
$days = ($hours/24);
$weeks = ($days/7);
$months = ($weeks/4);
$years = ($months/12);
if ($minutes > 525948){
$rmonths = ($months % $years);
$rweeks = ($weeks % $months);
$rhours = ($hours % $days);
$rminutes = ($minutes % $hours);
$rdays = ($days % $weeks);
$ryears = floor($years);
$Time = "$ryears Yr, $rmonths Mo, $rweeks Wk, $rdays D, $rhours H, $rminutes M";
}elseif ($minutes > 43829){
$rweeks = ($weeks % $months);
$rhours = ($hours % $days);
$rminutes = ($minutes % $hours);
$rdays = ($days % $weeks);
$rmonths = floor($months);
$Time = "$rmonths Mths, $rweeks Wks, $rdays Ds, $rhours Hs, $rminutes Ms";
}elseif ($minutes > 10080){
$rhours = ($hours % $days);
$rminutes = ($minutes % $hours);
$rdays = ($days % $weeks);
$rweeks = floor($weeks);
$Time = "$rweeks Weeks, $rdays Days, $rhours Hours, $rminutes Mins";
}elseif ($minutes > 1440){
$rhours = ($hours % $days);
$rminutes = ($minutes % $hours);
$rdays = floor($days);
$Time = "$rdays Days, $rhours Hours, $rminutes Minutes";
}elseif ($minutes > 60){
$rminutes = ($minutes % $hours);
$rhours = floor($hours);
$Time = "$rhours Hours, $rminutes Minutes";
}elseif ($minutes > 0){
$Time = "$minutes Minutes";
}elseif ($minutes == 0){
$Time = '0 Minutes';
}[/php]
the dots dont make a difference…actually it just outputs the dots as dots.

Jason2gs

2007-12-28 23:32:44

Wait, so what was the problem with it?

XcanadamanX

2007-12-29 09:58:11

you see in the first one how i did elseif(minutes) then next time i did elseif(hours) it was a comparison issue i guess.

Jason2gs

2007-12-29 14:51:21

Ah, alright :)

XcanadamanX

2007-12-29 14:53:49

right now its working pretty good.

XcanadamanX

2008-01-21 18:40:43

ok need some help here. some weird thing. explained below.
[php]if ($minutes > 1440){
$rdays = floor($days);
$rhours = $hours % ($rdays*24);
if ($rhours > 0){
$rminutes = $minutes % ($rhours * 60);
}else{
$rminutes = $minutes % ($rdays*1440);
}
$Time = "$rdays Days, $rhours Hours, $rminutes Minutes";[/php]

after 1 day, 4 hours and 59 minutes it will go 1 day, 5 hours and 240 mins. i dont know why.