This script echos the period where the value of the $variables array has a negative number.
I want to capture the number of the period where there is a negative value.
When the script is echoed (bayparkcapital.com/EE.php
) you can see the periods where the value of the associated variable is negative, 12. I need to capture the value in a new variable so the value of $period_to_solve is equal to 12, or an equivalent method. (I will loop thru the results)
Thanks for the help, here is the code
<?php
//connect to server
$mysqli = mysqli_connect("");
$username = $_SESSION['loggedin'];
//gather the topics
$loop_sql = "SELECT topic_id, topic_title, DATE_FORMAT(topic_create_t
ime, '%b %e %Y at %r') aS fmt_topic_create_time, topic_owner, INV_ID,INV_U_N, MS_F_NAME, MS_ID, CONT_DIST_1_1_08, cf_1_1_00, cf_2_1_00, cf_3_1_00, cf_4_1_00, ... cf_12_1_08 FROM invdb ORDER BY topic_create_time DESC";
$variables = array( 'cf_12_1_08'=>1,
'cf_11_1_08'=>2,
'cf_10_1_08'=>3,
. . . . . . . . . . . 'cf_1_1_00'=>108,
);
// and so on for E,F,G.....X
$loop_res = mysqli_query($mysqli, $loop_sql) or die(mysqli_error($mysqli))
;
echo $loop_sql;
while ($row = mysqli_fetch_assoc($loop_r
es)) {
foreach ($variables as $letter=>$number) {
if ($row[$letter] < 0) echo "$number is negative";
$period_to_solve = $number;
$rate = 0.15;
//First sum all of the period there is info for!
for ($x=0; $x<$period_to_solve; $x++)
{
$sum += $cashflow[$x] / pow($rate + 1, $x);
}
// NPV = {sum} + x/(1+rate)^4
// -{sum} * (1+rate)^4 = x
$final_period = 0 - $sum * pow(1+$rate,$period_to_sol
ve);
}
}
mysqli_free_result($loop_r
es);
//close connection to mysqli
mysqli_close($mysqli);
?>
Start Free Trial