[SOLVED]Warning: Division by zero

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

[SOLVED]Warning: Division by zero

Post by JellyFish »

It's been a while sense I've been on php code forum. Been working on client stuff.

I get a php error:
Warning: Division by zero in "the url" on line 286
line 286:

Code: Select all

$newwidth = ($newwidth/$imgheight);
line 284 to 286:

Code: Select all

list($imgwidth, $imghieght) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);
I don't understand why the php parser is saying that ($newwidth/$imgheight) is division by 0??? It's clearly not zero at all.

According to my arithmetics it would work perfect. Unless I'm going wrong somewhere.
Last edited by JellyFish on Sun Jan 14, 2007 4:33 pm, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

http://www.php.net/manual/en/function.list.php

List assigns variables backwards, that is, from right to left.

getimagesize() returns an array of 4 elements. Since you're only collecting two, you're collecting the right-most two (type & attr).

This should work:

Code: Select all

list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

and your spelling of $imgheight is different to variable you used in the list:
list($imgwidth, $imghieght) ;)
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Damn I feel stupid...
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

trust the parser ;)
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Thanks guys. Post out.
Post Reply