Topic awaiting preservation: PHP related table question (Page 1 of 1) |
|
---|---|
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
posted 06-07-2006 06:56
Hi all! |
Nervous Wreck (II) Inmate From: |
posted 06-07-2006 09:16
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 |
posted 06-07-2006 10:45
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 |
posted 06-07-2006 13:50
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.... |
posted 06-07-2006 15:03
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.... |
posted 06-07-2006 16:50
i figured it out with some help from a buddy...thanks! |
Nervous Wreck (II) Inmate From: |
posted 06-08-2006 07:44
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.... |
posted 06-08-2006 17:05
Regex was a thought but I was concerned that it would cause excessive stress on the server for a huge query like this. |