1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php variable wrong- which do i correct

Discussion in 'General Programming Chat' started by Quack, Apr 16, 2010.

  1. Quack

    Quack Newbie

    Joined:
    Sep 9, 2009
    Messages:
    34
    Likes Received:
    12
    Hi,
    using a amazon store script, receiving this warning,

    "Warning
    : Division by zero in /public_html/ireland/widget_featured.php on line 19"

    the warning reffers to this line: 1st line is 19,then 20 etc

    $percent = 80 / $height;
    $percentw = 80 / $width;
    if( $percentw < $percent ) $percent = $percentw;
    if( $percent > 1 ) $percent = 1;
    $width = (integer) ($percent * $width);
    $height = (integer) ($percent * $height);


    I understand that there may be a misspelling,just no idea what:confused:
    thanks in advance
     
    Last edited: Apr 16, 2010
  2. lord

    lord Junior Member

    Joined:
    Jan 21, 2009
    Messages:
    176
    Likes Received:
    251
    it appears that $height takes the value of 0 so i would give it a value

    something like

    PHP:
    if($height==|| $height==''$height=1;
    just before line 19 :)
     
    • Thanks Thanks x 1
    Last edited: Apr 16, 2010
  3. Quack

    Quack Newbie

    Joined:
    Sep 9, 2009
    Messages:
    34
    Likes Received:
    12
    thanks for the help,

    I,ve added the above like so

    $item = $parsed_xml->Items->Item;
    $imgURL = $item->MediumImage->URL;
    $width = $item->MediumImage->Width;
    $height = $item->MediumImage->Height;
    if($height==0 || $height=='') $height=1;
    $percent = 80 / $height;
    $percentw = 80 / $width;
    if( $percentw < $percent ) $percent = $percentw;
    if( $percent > 1 ) $percent = 1;
    $width = (integer) ($percent * $width);
    $height = (integer) ($percent * $height);

    without much luck,
     
  4. webcatpl

    webcatpl Junior Member

    Joined:
    Aug 12, 2008
    Messages:
    101
    Likes Received:
    9
    Maybe try to insert this line just before line 19:

    if (!isset($height)) {$height=1}
     
  5. Quack

    Quack Newbie

    Joined:
    Sep 9, 2009
    Messages:
    34
    Likes Received:
    12
    adding the code provided my lord, has removed the line 19 error, great start

    I should have added that I had the same error for both line 19 and 20

    so I only have the same issue with line 20
    I, thinking that I just add the same line again changing height to width
     
  6. Quack

    Quack Newbie

    Joined:
    Sep 9, 2009
    Messages:
    34
    Likes Received:
    12
    thanks lord, worked great ...this php looks fun, me thinks I want to learn this :)

    Again Thanks