PDA

View Full Version : [PHP] whats wrong with this.



XcanadamanX
12-25-2007, 08:55 PM
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.



<?
$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)
?>

osmm
12-27-2007, 02:24 AM
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
12-27-2007, 07:36 PM
Checking it out...

http://img45.imageshack.us/img45/5831/emotlolbm4.gif

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
12-27-2007, 08:03 PM
its actually a problem with

$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";
}

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
12-27-2007, 10:12 PM
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
12-27-2007, 10:14 PM
arent you meant to use dots in front of and behind variables in strings? like this:

$Time = ".$Seconds. Seconds";

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

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

$Time = ".$Minutes. Minutes, .$RSeconds. Seconds";
etc.

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

Jason2gs
12-27-2007, 10:18 PM
@ 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
12-27-2007, 10:21 PM
@ 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
12-29-2007, 01:18 AM
Oh my. Looks like CanadaMan just

EPIC FAILED!

XcanadamanX
12-29-2007, 02:23 AM
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.


$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';
}
the dots dont make a difference...actually it just outputs the dots as dots.

Jason2gs
12-29-2007, 04:32 AM
Wait, so what was the problem with it?

XcanadamanX
12-29-2007, 02:58 PM
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
12-29-2007, 07:51 PM
Ah, alright :)

XcanadamanX
12-29-2007, 07:53 PM
right now its working pretty good.

XcanadamanX
01-21-2008, 11:40 PM
ok need some help here. some weird thing. explained below.

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";

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