Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Pulling Data from a specific Date?
Old 10-05-2010, 07:17 AM Pulling Data from a specific Date?
Novice Talker

Posts: 5
Trades: 0
I want to pull a value from the "previous" december but I don't know how.

I know how to pull the value from January of a month but that's it.

PHP Code:
$resp '';
$year'';

$i=0;

while (
$row mysql_fetch_array($rsMYSQL_ASSOC)) 
    {
    
$mnth=$row["month_no"];

    
$prev_month=$row["prior_month"];

[
B]    $first_month=$row["jan_month"];[/B]

    
$since_inception=($row["gross_nav"])-($row["fund_begin_price"])/($row["fund_begin_price"]);

    
$performance=((($row["gross_nav"])-1)*100);

    if(
$prev_month == 0)
    {
    
$net_nav=0;
    }
    else
    {
    
$net_nav=((($row["gross_nav"]-$row["prior_month"])/$row["prior_month"])*100);
    }

    if(
$first_month == 0)
    {
    
$return=0;
    }
    else
    {
        if(
$mnth == 1)
        {
        
$return=((($row["gross_nav"]-$row["prior_month"])/$row["prior_month"])*100);
        }
        else
        {
        
$return=[B]((($row["gross_nav"]-$row["jan_month"])/$row["jan_month"])*100);[/B]
        }
    }
            
    

    
$resp .= '<nav date="'.$row["cost_date"].'" gross_nav="'.$row["gross_nav"].'" dividend="'.$row["dividend_units"].'" net_nav="'.number_format($net_nav2'.'',').'%" return="'.number_format($return2'.'',').'%" since_inception="'.round($performance,4).'%"/>';    
    
        } 
Focus on the bold text. Where I used January of the month. What I want is to substitute it with December of the previous year. Can you help me please?

Last edited by chrishirst; 10-05-2010 at 07:35 AM..
yabyab is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-05-2010, 07:34 AM Re: Pulling Data from a specific Date?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Why are you messing about with PHP when the database server can do that the FAR more efficiently?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-06-2010, 01:15 AM Re: Pulling Data from a specific Date?
Novice Talker

Posts: 5
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Why are you messing about with PHP when the database server can do that the FAR more efficiently?
Hello Chrishirst. Thank you for replying.

The database is mySQL but I don't know how to adjust the database I use mySQL Query Browser.
yabyab is offline
Reply With Quote
View Public Profile
 
Old 10-06-2010, 03:09 AM Re: Pulling Data from a specific Date?
Novice Talker

Posts: 5
Trades: 0
Basically what I need is to call the previous month (which is december) when month == 1 (January) and save that month's value and then use this value with my calculations.


Something like

if ($mnth == 1) <-- January
{
$dec_month=$row["prior_month"];
}

then I use $dec_month on my calculations.. but my syntax doesn't work :/
yabyab is offline
Reply With Quote
View Public Profile
 
Old 10-07-2010, 02:25 AM Re: Pulling Data from a specific Date?
Novice Talker

Posts: 5
Trades: 0
okay I solved the problem, it was easy I just am not familiar with php syntax (even though it's pretty close to C++).

if f ($mnth == 1)
{
$december=
$row["prior_month"];
}

So, now we have the value of the previous december and using the variable $december in my calculations and finally can calculate the Year to Date fund performance.


yabyab is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Pulling Data from a specific Date?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.71713 seconds with 12 queries