Changing a Field in a Database Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephan wintgens
    New Member
    • Jun 2007
    • 1

    #1

    Changing a Field in a Database Table

    I need to calculate a capital and put the information inside of a table, but something doesn't work well, can you help me.what i try to do is to calculate when final capital will be equal to the initial one and secondly the intereste slow down eatch year. so with out any table i have no problem , but i can not make work the table, i don't know what i need to do.
    [code=php]
    <html><head><ti tle>calcul du capital</title></head>
    <body bgcolor="#ffcc9 9">
    <h1>Calcul du capital</h1>
    <?php
    $capital_initia l=100;
    $taux_initial=2 .5;
    $capital_final= 1000;
    $annees=2007;

    print "<h2>Tablea u de l'évolution du capital</h2><BR>";

    $capital=$capit al_initial;
    $taux=$taux_ini tial;
    echo "<TABLE BORDER='1'>";
    echo "<tr><td>annees </td><td>taux d'interet</td><td>capital</td></tr>";

    while ($capital<$capi tal_final)
    {

    echo"<TR>";
    $capital=$capit al*(1+$taux/100);
    echo"<TR>"
    for($i=0,$i<??? ,$i++){
    echo "<tr><td>". $row["annees"]."</td><td>".$row["taux"]."</td><td>".$row["capital"]."</td></tr>;
    }
    $annees=$annees +1
    $taux=$taux-.1

    echo "</TABLE>";
    }
    ?>
    [/code]
    thanks
    Last edited by Atli; Jun 16 '07, 03:22 AM. Reason: Added code tags
  • webshzu
    New Member
    • Jun 2007
    • 1

    #2
    The code below will create table output for you. With your orignal code you would never see the output because the criteria to complete the "while" statement is never met. The interest rate became negative before capital exceeded capital_final, which then caused the value of capital to decrease.

    So I made a few changes in your formula just to show you the table results.

    [code=php]
    <body bgcolor="#ffcc9 9">
    <h1>Calcul du capital</h1>
    <h2>Tableau de l'évolution du capital</h2>
    <TABLE BORDER='1'>
    <tr>
    <th>annees</th>
    <th>taux d'interet</th>
    <th>capital</th>
    </tr>

    <?php
    $capital_initia l=100;
    $taux_initial=2 .5;
    $capital_final= 120;
    $annees=2007;
    $capital=$capit al_initial;
    $taux=$taux_ini tial;
    echo "capital = " . $capital . "<br />taux = " . $taux . "<br />capital_fina l = " . $capital_final;

    while ($capital < $capital_final) {
    ?>
    <tr>
    <td>
    <?php echo $annees; ?>
    </td>
    <td>
    <?php echo $taux; ?>
    </td>
    <td>
    <?php echo $capital; ?>
    </td>
    </tr>
    <?php
    $capital=$capit al*(1+($taux/100));
    $annees=$annees +1;
    $taux=$taux-.1;
    }
    ?>
    </TABLE>
    </body>
    [/code]
    Last edited by Atli; Jun 16 '07, 03:23 AM. Reason: Added code tags

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Stephan. Welcome to TSDN!

      What is your code doing? What is it supposed to be doing?

      P.S., Changed thread title. We know it's a PHP problem; that's why you posted it in the PHP forum :)

      Comment

      Working...