one problem on the second script you are trying to use variables that are in
an array.
if this is where you are talking about
you need to specify the array[key]
while ($myrow=DB_fetch_array($result)){
$difference = ($budget - $actual);
$difference = ($myrow[budget] - $myrow[actual]);
printf(TRTD%s/TDTD%s/TDTD%s/TDTD%s/TDTD%s/TDTD%s/T
- Original Message -
From: Michael O'Neal [EMAIL PROTECTED]
To: Php-General@Lists. Php. Net [EMAIL PROTECTED]
Sent: Wednesday, October 24, 2001 1:18 PM
Subject: [PHP] Trying to subtract...no luck. (Long Code)
Hi. I'm trying to figure out how to subtract 1 variable from another, but
I'm not having any luck.
It works on this page:
?php
$db_name = comanche;
$table_name = ProjectTasks;
$connection = @mysql_connect($db,$user,$pass) or die(Couldn't
Connect.);
$db = @mysql_select_db($db_name, $connection) or die(Couldn't select
database.);
$sql =SELECT budget,actual FROM $table_name;
$result = @mysql_query($sql, $connection) or die(Couldn't execute
query.);
while ($row = mysql_fetch_array($result)) {
$budget=$row['budget'];
$actual=$row['actual'];
$difference = ($budget - $actual);
echo $budget - $actual = $differencebr;
}
$num = @mysql_num_rows($result);
?
But not on this page:
---BEGIN LONG PHP STUFF --
?php
$title = Tasks Maintenance;
include(../inc/hdr.php);
include(header.inc);
include(DateFunctions.inc);
if (!isset($ProjectID)){
echo PThis page must be called from the projects list page with the
tasks link. Alternatively, you can enter the link as
Tasks.php?ProjectID=iProjectID number/iPA HREF=' . $rootpath .
/Projects.php'Project List/A;
exit;
}
if ($submit) {
//initialise no input errors assumed initially before we test
$InputError = 0;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
//first off validate inputs sensible
if (strlen($TaskName) 50 OR strlen($TaskName)==0) {
$InputError = 1;
echo BRThe task name must be entered and be fifty characters or
less long;
} elseif (!is_date($EarliestStart)) {
$InputError = 1;
echo BRThe date the task was initiated must be specified in the
format dd/mm/;
} elseif (!is_numeric($ExpectedDuration) || $ExpectedDuration0){
$InputError = 1;
echo BRThe expected duration of the task must be specified as a
number - greater or equal to 0; }
if ($InputError !=1){
$SQL_EarliestStart = FormatDateForSQL($EarliestStart);
if (isset($SelectedTask)) {
$sql = UPDATE ProjectTasks SET TaskName='$TaskName',
TaskDescription='$TaskDescription', EarliestStart='$SQL_EarliestStart',
TaskChampion='$TaskChampion', ExpectedDuration=$ExpectedDuration,
Status='$Status', budget='$budget', actual='$actual' WHERE TaskID =
$TaskID;
$result = DB_query($sql,$db);
if (DB_error_no($db) !=0) {
echo The task could not be updated because - .
DB_error_msg($db) . The SQL statement used for the update was:BR$sql;
} else {
echo Ptask updated;
unset($SelectedTask);
unset($TaskName);
unset($TaskDescription);
unset($TaskChampion);
unset($EarliestStart);
unset($ExpectedDuration);
unset($Status);
unset($budget);
unset($actual);
}
} else { //not a new task
$sql = INSERT INTO ProjectTasks (ProjectID, TaskName,
TaskDescription, EarliestStart, TaskChampion, ExpectedDuration, Status,
budget, actual) VALUES ($ProjectID, '$TaskName', '$TaskDescription',
'$SQL_EarliestStart', '$TaskChampion', $ExpectedDuration, '$Status',
'$budget', '$actual');
$result = DB_query($sql,$db);
if (DB_error_no($db) !=0) {
echo The task could not be added because - .
DB_error_msg($db) . the SQL used to insert the new task was:BR .
$sql;
} else {
echo PTask inserted;
unset($TaskName);
unset($TaskDescription);
unset($TaskChampion);
unset($EarliestStart);
unset($ExpectedDuration);
unset($Status);
unset($budget);
unset($actual);
}
}
} else {
echo BRValidation failed, no updates or deletes took place.;
}
} elseif ($delete) {
//the link to delete a selected record was clicked instead of the submit
button
$sql=DELETE FROM ProjectTasks WHERE TaskID=$TaskID;
$result = DB_query($sql,$db);
$sql=DELETE FROM TaskDependancies WHERE TaskID=$TaskID;
$result = DB_query($sql,$db);
$sql=DELETE FROM TaskDependancies WHERE