Re: [PHP] Trying to subtract...no luck. (Long Code)

2001-10-24 Thread Jim Lucas

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 

Re: [PHP] Trying to subtract...no luck. (Long Code)

2001-10-24 Thread Chuck Theobald

Another way to accomplish this, preferred in my mind, is:

while ($myrow = db_fetch_array($result)) :
  while (list($key,$val) = each($myrow)) :
$$key = $val;
  endwhile;
  $difference = $budget - $actual;
  . . .
endwhile;

Chuck


At 1:34 PM -0700 10/24/01, Jim Lucas wrote:
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]);


Chuck Theobald, Technology Manager
ERIC Clearinghouse on Educational Management
5207 University of Oregon, Eugene, OR, 97403-5207
800-438-8841
* 541-346-1662 (voice) * 541-346-2334  (fax) * 541-337-0182 (cell) *
* http://eric.uoregon.edu/ * mailto:[EMAIL PROTECTED] *



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Trying to subtract...no luck. (Long Code)

2001-10-24 Thread Chris Hayes


Jeez michael, i'm sorry  but i am not going to go 
through all of your code. 

I do have a suggestion for you, without looking at 
the code.

As you know. php has flexible variables. I mean, if 
you say $a=1 then $a is an integer, if you say 
$b='i' then $b is a string.
Very easy to make code quickly, but for the larger 
scripts it can be a pit trap.

I think that while you intended the variables to be 
numbers, they somehow turned into strings. Maybe 
you added a (empty) string somewhere ($a .='').

Several ways to deal with it.
First have a look at what is in the variable:

echo 'hrstring a is ['.$a.']';
i always add something around the string to see 
spaces.

Another thing you can try is to force the value 
into an integer.
I think something like

$c= intval($a) - intval ($b);

but have  a look around the manual to be sure.

hth, let me know at my own email if it helped?

Chris


---
-
--  C.Hayes  Droevendaal 35  6708 PB Wageningen  
the Netherlands  --
---
-

 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Trying to subtract...no luck. (Long Code)

2001-10-24 Thread Michael O'Neal

Thanks all...I got what I needed.  I'm amazed at how many different ways
there are to do the same thing!


mto

-- 

Michael O'Neal
Web Producer/ Autocrosser
ST 28 '89 Civic Si
-
 M   A   N   G   O
B  O  U  L  D  E  R
-
http://www.thinkmango.com
e- [EMAIL PROTECTED]
p- 303.442.1821
f- 303.938.8507


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]