Jump to content

change from last record


brown2005

Recommended Posts

Hi, I have the following

 

while($years_array = mysql_fetch_array($years_query))

{

 

$year = $years_array['year'];

$year_rank = number_format($years_array['rank']);

$year_change = number_format($years_array['change']);

 

 

echo"  <tr>

        <td width='50' align='center'><a href='' class='red'>$year</a></td>

        <td width='75' align='center'><a href='' class='red'>$year_rank</a></td>

        <td width='75' align='center'><a href='' class='red'>$year_change</a></td>          

    </tr>";

 

at the moment the change is 0, but what I want is say i have the following

 

2006  1,000,000    0

2007  500,000        +500,000

 

what I want to do is be able to display the +500,000 if this ok cause that is the difference between 2006 and 2007, any help would be appreciated?

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/41239-change-from-last-record/
Share on other sites

For 2 years it will be no prob but if it's going to be continuous you may want to do the calculation and insert it into the table before you display it. Reason is everytime another year is added you will have to add another calculation to the script. But if you do the calcultion and put it in the table, when you output you will only need to echo the info from the table.  Understand?

try this ok.

 

<?php

while($years_array = mysql_fetch_array($years_query))
{

$year = $years_array['year'];
$year_rank = number_format($years_array['rank']);
$year_change = (number_format($years_array['change'])+(number_format($years_array['rank'])));
        
   
echo"         <tr>
                <td width='50' align='center'><a href='' class='red'>$year[/url]</td>
                <td width='75' align='center'><a href='' class='red'>$year_rank[/url]</td>
                <td width='75' align='center'><a href='' class='red'>$year_change[/url]</td>             
            </tr>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.