Results 1 to 3 of 3

Thread: How to Retrive data of the Previous month with Loop

  1. #1
    Join Date
    Feb 2009
    Posts
    105

    How to Retrive data of the Previous month with Loop

    Hi,

    I'm using a php & MySQL. In the MySQL table name Employee. it has 3 fields EmpYear, EmpName, EmpDateAdded where data are records from january to december 2008. On the otherhard, In my php code i created also a table with 4 columns ColYear, ColName, ColDateAdded, ColPrevYear. My concern is on the ColPrevYear, how do i code in php to get the data in fieldScore to display in ColPrevYear assuming that i am now viewing data for the month of July and i want to display in ColPrevYear the last month(June). However, if no year found for the month of June, it will loop back on the next previous months until score is found.

    Anybody please help me with this...

    Thanks in advance.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: How to Retrive data of the Previous month with Loop

    You can achieve this in one of Several ways ...

    One way is to build an array using a numeric index as you fetch results from your data source. Then as you build your html code, use $yourArray[$i - 1] to access the previous element in your array.

    Another way is to store off the currently fetched data in a variable and then refer back to that variable as "previous".

  3. #3
    Join Date
    Oct 2008
    Posts
    167

    Re: How to Retrive data of the Previous month with Loop

    PHP Code:
    <?php
    include 'init.php';

    if (!
    is_authed())
    {
            
    header("Location: http://xxxx/wewewe/wee.ph");
            exit;
    }
    $ID $_SESSION['ID'];

    $results mysql_query("SELECT * FROM `WorkExperience` WHERE ID=$ID");
    $row mysql_num_rows($results);
    if(
    $row == 0)
    {
            
    mysql_query("INSERT INTO `WorkExperience` (ID) VALUES ('$ID')");
    }

    mysql_query($query);
    }

    if(
    $_POST['next'])
    {
            
    header("Location: gotonextpage.php");
            exit();
    }

    $query "SELECT * FROM `WorkExperience` WHERE ID=$ID";
    $results mysql_query($query);
    $data mysql_fetch_array($results);


    $CountryOfEmployment $data['CountryOfEmployment'];
    $CommencementDay $data['CommencementDay'];
    $CommencementMonth $data['CommencementMonth'];
    $CommencementYear $data['CommencementYear'];

    ?>
    This should work for you. Obviously change the SQL to suit your database, etc.

Similar Threads

  1. Replies: 2
    Last Post: 16-01-2012, 12:34 PM
  2. Replies: 5
    Last Post: 05-04-2011, 06:47 PM
  3. How to select previous month's date?
    By Saaz in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 02:07 PM
  4. How to create excel graph data for a month in Windows Vista
    By AK_Chopra in forum Windows Software
    Replies: 2
    Last Post: 04-06-2009, 07:58 PM
  5. How much Data you download per month ?
    By Shantanu12 in forum India BroadBand
    Replies: 8
    Last Post: 19-01-2009, 09:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,755,317.62225 seconds with 16 queries