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
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?

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.