Help with php and mysql

Discussion in 'PHP' started by Quoolu (Christopher), Jan 26, 2011.

  1. #1
    Hello,

    I have this website I want to build for personal use but I have come to a problem. I have a database with all these rows of transactions. But each row needs some values from the previous row to calculate the values for the row. I also need this to loop again and again through each transaction until there are no more rows. So my big question is how do I take values calculate to get a number and use them on the next row again and again until there's no more rows.

    Thanks
     
    Quoolu (Christopher), Jan 26, 2011 IP
  2. John Mahoney

    John Mahoney Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't understand your post completely, but here's a good show.

    An example of how math can be grabbed, carried to the next row, and more math done to that number.

    
    <?php
    
    /** 
     * @Author: John Mahoney
     * @Rights: Use as you wish! 
     **/
    
    // Do your mysql connect and db select stuff
    
    $rows_sql = "SELECT * FROM db_table";
    $rows   = mysql_query($rows_sql);
    
    // If it came back Empty Handed
    if (!$rows) {
     die('The Query Did Not Work '.mysql_error());
    }
    
    $math = 0;
    while ($row = mysql_fetch_array($rows)) {
      $number_to_add = $row['row_with_math'];
     
    
    $math = $math+number_to_add;
    }
    
    echo $math;  //This will should echo the Math behind the Product of All Your Rows.
    ?>
    
    PHP:
    There may be a faster more efficient way, this is just the quickest way to get you started. No one else responded to you, so I figured I would see what I can do.

    - :cool:
     
    John Mahoney, Jan 27, 2011 IP
  3. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #3
    SELECT SUM(column) as `total` FROM `table` WHERE 1
    PHP:
     
    Alex Roxon, Jan 27, 2011 IP