SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Malfunctioning Function - Why?

    Aw, now this one really has me baffled. The first part of my function is as follows:
    Code:
    function DBPaging($RecordCount, $PageSize, $PageCurrent)
       {
       // echo $RecordCount . " " . $PageSize . " " . $PageCurrent;
       // die();
            // Determine the total pages requested
    	$PageCount = $RecordCount / $PageSize;
    The argument values for the function are 337, 20, and 3, respectively, as they display in the echo statement (when it isn't commented out). So why am I getting this error on the division statement?

    Warning: Division by zero
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try echoing the variables and see what they really are.

    Aaron
    Aaron Brazell
    Technosailor



  3. #3
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sketch
    Try echoing the variables and see what they really are.

    Aaron
    I did that already. As I said, in my original post, the variable values were 337, 20, and 3 respectively, when I un-commented out the echo statement.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the problem is $RecordCount is being divided by Zero.

    before feeding the values to the function, try echo the values OUTSIDE the function and see what is really being fed to the fn.

  5. #5
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried the code...
    PHP Code:
    <?
    error_reporting
    (E_ALL E_NOTICE);
    function 
    DBPaging($RecordCount$PageSize$PageCurrent)
       {
     echo 
    $RecordCount " " $PageSize " " $PageCurrent;
       
    // die();
            // Determine the total pages requested
        
    $PageCount $RecordCount $PageSize;
        echo 
    $PageCount;
        }

    DBPaging(337,20,3);
    ?>
    It works fine for me, with the result showing 337 20 316.85 (formatting ).
    Lats...

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by astericks
    Well the problem is $RecordCount is being divided by Zero.

    before feeding the values to the function, try echo the values OUTSIDE the function and see what is really being fed to the fn.
    Good suggestion. I had actually done that already, but not in such a way that the problem would be revealed. What it showed was that I am calling the DBPaging function twice! The first time performed just fine, it's the second one that barfed. Here's the code from the calling program:
    Code:
    DBPaging::DBPaging($RecordCount, $this->pagesize, $this->pagecurrent);
    
    list ($RowStart, $RowEnd, $PageCount, $PageCurrent) =
        DBPaging::DBPaging($RecordCount, $this->pagesize, $this->pagecurrent);
    I thought what I had to do was call the function (first statement) then retrieve the variables with the list statement. I took a closer look at the manual and realized the error of my ways.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •