Location: PHPKode > projects > Gsys > treasury/user_transactions.php
<?PHP
//Filename : user_transactions.php
//Description : Show a user their transactions.
//Author :  darc
//Last modified :  2006.12.20

    include '../includes/auth.php';
    include '../includes/db.php';
?>

<html>

<head>
<title>Epsilon-Gamma Local Brotherhood Services</title>
<link href="../includes/index.css" rel="stylesheet" type="text/css">
</head>

<body class="body">
<br />
<table width="810" height="626" border="0" align="center" cellpadding="15">
  <tr> 
    <td height="128" colspan="2"><img src="../images/eg_banner.gif" width="810" height="172"></td>
  </tr>
  <tr> 
    <td width="27%" height="488" valign="top"> <?php include '../includes/nav.inc'; ?></td>
    <td width="53%">
      <?php
	session_start();
	 $user_pin = $_SESSION['pin_num'];
	
	//SQL query to get all the user's transactions, sort descending
         $sql = "SELECT amount, transaction_num, date_time, added_by, description FROM financial INNER JOIN brothers ON financial.pin_num = brothers.pin_num WHERE financial.pin_num = '$user_pin' GROUP BY amount, transaction_num, date_time, added_by, description ORDER BY date_time DESC";
         $result = mysql_query($sql,$connection) or die(mysql_error());
	 
	//SQL query to get the current balance of the user ~ IE:  SUM(amount)
	 $sql_balance = "SELECT SUM(amount) AS sum_amount FROM financial INNER JOIN brothers ON financial.pin_num = brothers.pin_num WHERE financial.pin_num = '$user_pin' ORDER BY date_time";
         $sql_balance_result = mysql_query($sql_balance,$connection) or die(mysql_error());

	 //Set the current balance
	 $row_bal =mysql_fetch_array($sql_balance_result);
	 $balance = $row_bal[sum_amount];

         echo "
	<center><h2>Transaction List  ||  Generated ";

		echo date("F j, Y, g:i a");

         echo "
		</h2></center>
		<br><br>

		<table border=\"3\" bordercolor=\"#000000\">

		<tr>
		<td width=\"10%\" align=\"center\"><strong>Transaction Number</strong></td>
		<td width=\"15%\" align=\"center\"><strong>Date Posted</strong></td>
		<td><strong>Posted By</strong></td>
		<td><strong>Amount</strong></td>
		<td><strong>Balance</strong></td>
		<td><strong>Description</strong></td>
		</tr>";

	//Loop through every row, outputting information and updating balance after transaction (at bottom of loop)
		while ($row = mysql_fetch_array($result))
		{
	                $transaction_num = $row['transaction_num'];
	                $date_time = $row['date_time'];
	                $amount = $row['amount'];
	                $posted_by = $row['added_by'];
	                $description = $row['description'];
	         echo "<tr><td align=\"center\">";

	         echo($transaction_num);
	         echo "</td><td align=\"center\">";
	         echo($date_time);
	         echo "</td><td>";
	         echo($posted_by);
	         echo "</td><td>$";
	         echo($amount);
	         echo "</td><td>$";
	         if($balance < 0)
        	 echo "<font color=\"red\"><b>$balance</b></font>";
    		 else
        	 echo "$balance";
	         echo "</td><td>";
	         echo($description);
	         echo "</td></tr>";

			//Update balance for next iteration (NOTE:  Do this *AFTER* displaying current balance)
			$balance -= $row['amount']; 
		}
//CLOSE LOOP

	         echo "
		</table>"; ?>
    </td>
  </tr>
</table>
</body>
</html>
Return current item: Gsys