SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32

Thread: Need to calaculate new number from old number and put in to different row

  1. #26
    SitePoint Member silo23's Avatar
    Join Date
    Jun 2010
    Location
    UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actual output required is monthly miles saved back to db then out to chart.

    Current problem, using kduv's solution using the db and PHP code (post 16 above), I can get the code to save monthly_miles back to db on my test server (XAMPP) but when I upload it and try it on my live sever it doesn't work.

  2. #27
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,456
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    "doesn't work" is not a recognized error message
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #28
    SitePoint Member silo23's Avatar
    Join Date
    Jun 2010
    Location
    UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may not be a recognized error message, but it is an accurate description of what didn't happen.

    Using kduv's code, this works on my XAMPP setup but not on my hosting server.

    Code:
        $last_odometer = ($i == 0) ? $columns['odometer'] : $rows[$row - 1]['odometer'];
        $month_total = $columns['odometer'] - $last_odometer;
    Unfortunately, for the life of me, I cannot understand how the above piece of code saves it's output back to the monthly_mileage column.

  4. #29
    SitePoint Member silo23's Avatar
    Join Date
    Jun 2010
    Location
    UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've placed the code,
    Code:
    <?php error_reporting(E_ALL);
    ini_set('display_errors', 1); ?>
    at the beginning of the page to try and track errors and i get this error back

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test\Mileage3_output.php on line 95

    Still using kduv's code from post 16. Any help, observations or quips more than welcome.

  5. #30
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,849
    Mentioned
    16 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    foreach ($rows as $row => $columns
    If that is the offending line then it means that $rows is not a valid array. Its probably not an array at all, so at this point you have to start investigating why your two setups are different.

    Check the files closely and if you do not spot something obvious then a good bet is that either your db credentials on your live server are incorrect, OR you do not have any matching data in your database OR an include file is not being found.

    Otherwise start by adding the line:
    PHP Code:
    var_dump($rows); 
    and work you way back through the variables till you get proof of where the error is occurring.

  6. #31
    SitePoint Member silo23's Avatar
    Join Date
    Jun 2010
    Location
    UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, in kduv's original code it says
    Code:
    $rows = ''; // array of rows from database results
    Which I might be supposed to fill in or not. I've been reading up and googling as much as I can but I'm afraid I don't know.

  7. #32
    SitePoint Member silo23's Avatar
    Join Date
    Jun 2010
    Location
    UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to say thanks for everyone's help (especially Cups) there is now a working solution.

Tags for this Thread

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
  •