Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-02-2009
Member
 
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.
Reply With Quote
  #2  
Old 27-02-2009
Member
 
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".
Reply With Quote
  #3  
Old 27-02-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Retrive data of the Previous month with Loop"
Thread Thread Starter Forum Replies Last Post
How to retrieve previous iPhone data such as contacts through icloud joey1408 Portable Devices 2 16-01-2012 12:34 PM
How to get a summarized sheet of all the data sheets of a month Kindle Windows Software 5 05-04-2011 06:47 PM
How to select previous month's date? Saaz Software Development 3 14-11-2009 02:07 PM
How to create excel graph data for a month in Windows Vista AK_Chopra Windows Software 2 04-06-2009 07:58 PM
How much Data you download per month ? Shantanu12 India BroadBand 8 19-01-2009 09:46 AM


All times are GMT +5.5. The time now is 10:44 AM.