Forum Moderators: coopster

Message Too Old, No Replies

Balance Checking and Limits before Adding

         

scottdufour

6:30 pm on May 26, 2009 (gmt 0)

10+ Year Member



I'm writing a program that keeps track of student fees/tuition per semester and year. I would please like some ideas on how to code this limit checking which will be running balances per year. I have these details:

max annual scholarship per student: 15000.00
max annual tuition/books/fees per: 12000
max annual for housign: 3000
max housing per semester: 1500

max amount for the program over the years: 60000

Do I use simple functions? or?

coopster

1:05 pm on May 27, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would probably add a year column to the "maximums" table. Sum the "transactions" table for any given "cost type" and compare to the "annual maximum allowance" to determine acceptability.

scottdufour

1:12 pm on May 27, 2009 (gmt 0)

10+ Year Member



Sounds good. Any code examples of how I should do this? I can't seem to think on how the code would look since I will have to continuously check back and forth betweeen the maximums table and all.

coopster

1:19 pm on May 27, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, you have it correct, you will need to compare table values. If I were you I would first concentrate on the sum total for any given students' expenses in any given year.

scottdufour

1:29 pm on May 27, 2009 (gmt 0)

10+ Year Member



Can you possibly steer me in the right direction by providing an example of what the comparison code would look like before the form is submitted? I have a "add semester expenses" form and then the code to add to the semester table

newsemexpense.php:

<form method="POST" action="postsemexpense.php" onsubmit="return isReady(this)">
<table border="0" width="75%" id="table1">
<tr>
<td width="332"><b>Student:</b></td>
<td><input type="hidden" value="<?php echo $row[fname];?> <?php echo $row[mname];?> <?php echo $row[lname];?>" name="student1" size="53" style="border-style: solid; border-width: 1px"><?php echo $row[fname];?> <?php echo $row[mname];?> <?php echo $row[lname];?></td>

</tr>

<TR>
<td width="332"><b>Student ID#:</b></td>
<td>
<input type="hidden" value="<?php echo $row[id1] ; ?>" name="id1" size="53" style="border-style: solid; border-width: 1px"><?php echo $row[id1] ; ?></td>
</tr>

<tr>
<td width="332"><b>SS #:</b></td>
<td>
<input type="hidden" value="<?php echo $row[ss] ; ?>" name="ss" size="53" style="border-style: solid; border-width: 1px"><?php echo $row[ss] ; ?></td>
</td>
</tr>
<tr>
<td width="332"><b>Year:</b></td>
<td>
<select size="1" name="year1" style="border-style: solid; border-width: 1px">
<option selected value="2009">2009</option>
<option value="2010">2010</option>

<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>

</select></td>
</tr>
<tr>
<td width="332"><b>Semester:</b></td>
<td>
<select size="1" name="semester1" style="border-style: solid; border-width: 1px">
<option selected value="Winter Q1">Winter Q1</option>
<option value="Spring Q1">Spring Q1</option>
<option value="Summer Q1">Summer Q1</option>
<option value="Fall Q1">Fall Q1</option>
<option value="MiniMester">MiniMester</option>
<option value="Intercession">Intercession</option>

</select></td>
</tr>
<tr>
<td width="332"><b>Tuition:</b></td>
<td>
<input onkeypress="return handleEnter(this, event)" type="text" name="tuition1" size="53" style="border-style: solid; border-width: 1px"></td>
</tr>
<tr>
<td width="332"><b>Fees:</b></td>
<td>
<input onkeypress="return handleEnter(this, event)" type="text" name="fees1" size="53" style="border-style: solid; border-width: 1px"></td>
</tr>
<tr>
<td width="332"><b>Books/Supplies:</b></td>
<td>
<input onkeypress="return handleEnter(this, event)" type="text" name="books1" size="53" style="border-style: solid; border-width: 1px"></td>
</tr>
<tr>
<td width="332"><b>Housing/Room/Board:</b></td>
<td>
<input onkeypress="return handleEnter(this, event)" type="text" name="housing1" size="53" style="border-style: solid; border-width: 1px"></td>
</tr>

<input type="hidden" name="total1" size="53" style="border-style: solid; border-width: 1px"></td>

</table>
<p><input type="submit" value="Submit" name="B1" style="border-style: solid; border-width: 1px"><input type="reset" value="Reset" name="B2" style="border-style: solid; border-width: 1px"></p>
<input type="hidden" name=user value="">
<input type="hidden" name=dateadded value="<?php echo $today;?>">
</form>

postsemexpense.php:

<?php
session_start();

if (!isset($_SESSION['user']))
{
header("Location: login.php");
}

$total1 = $_POST['tuition1'] + $_POST['fees1'] + $_POST['books1'] + $_POST['housing1'];
$con = mysql_connect("localhost","root","shelbyp51");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("scholar", $con);
$sql="INSERT INTO semester (year1, semester1, tuition1, fees1, books1, housing1, total1, user, student1,ss,id1,dateadded)
VALUES
('$_POST[year1]','$_POST[semester1]','$_POST[tuition1]','$_POST[fees1]','$_POST[books1]','$_POST[housing1]','$total1','$_SESSION[user]', '$_POST[student1]', '$_POST[ss]', '$_POST[id1]','$_POST[dateadded]')";

$sqlhist="INSERT INTO historysem (year1, semester1, tuition1, fees1, books1, housing1, total1, user, student1,ss,id1,dateadded)
VALUES
('$_POST[year1]','$_POST[semester1]','$_POST[tuition1]','$_POST[fees1]','$_POST[books1]','$_POST[housing1]','$total1','$_SESSION[user]', '$_POST[student1]', '$_POST[ss]', '$_POST[id1]','$_POST[dateadded]')";


if (!mysql_query($sql,$con))

{
if (mysql_errno() == 1062)

die('This student already has expenses for this year and semester. Please use the Update Semester Expenses section of this site to make changes.<br><br><center><br><form action=usemstudentsearch.php><input type=submit value="Return to Main Search Form" name=button1 style=border-style: solid; border-width: 1px></form>');

else
{
mysql_query($sqlhist,$con);
echo "Student Semester Expenses Sucessfully Added!";
}
}
mysql_close($con)
?>

PLEASE HELP IF YOU CAN.