![]() Topic awaiting preservation: PHP related table question (Page 1 of 1) |
|
---|---|
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
![]() Hi all! |
Nervous Wreck (II) Inmate From: |
![]() I would parse it by line, and use $c as the cumulative result. I would use preg_match_all with something like /[0-9]+/, I would intval() the resultant value I wanted, add it to $c, and append it and the delimiter to the end, output the resultant line to an output buffer. If empty($matches), ignore the line (rather, just echo it unchanged). |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() code: $strQuery = "SELECT date, unique, cumulative FROM TABLE ORDER BY date ASC" $hRes = mysql_query ( $strQuery ); $iCum = 0; while ( $arrRow = mysql_fetch_array ( $hRes ) ) { $iCum += $arrRow['unique']; $strUpdateQuery = "UPDATE table SET cumulative = {$iCum} WHERE date = '{$arrRow['date']}'"; mysql_query ( $strUpdateQuery ); }
|
Bipolar (III) Inmate From: Australia |
![]() Do you need to store it in the database table, you might as well calculate it when you output the table results to html or whatever as you print each line. Kind of redundant storing it in the database, depending on what you are doing with it of course. |
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
![]() I have no need to store the data in the db. This is one of those, "Hey can you do this with the data" things that my boss asked for. |
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
![]() i figured it out with some help from a buddy...thanks! |
Nervous Wreck (II) Inmate From: |
![]() Hahaha. I hope it's obvious I didn't think you had access to the db beyond doing the table dump; otherwise, using SQL vs regex was a rather blatantly obvious choice. |
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
![]() Regex was a thought but I was concerned that it would cause excessive stress on the server for a huge query like this. |