Page 1 of 1

SQL CASTING PROBLEM

Posted: Tue Sep 14, 2010 10:49 am
by at_rcc
Hi i wanted to select a field called transaction amount in table transaction of debtors , and it does no seem to be able to retrieve the data correctly and i am unable to know how to do casting here is part of the script

//getting values from post/form
$customer = $_POST["customer_id"];
$amount = $_POST["amount_paid"];

$sql = "SELECT tra_outstanding FROM transaction WHERE tra_customer_id='".$customer."'";
$result = nuRunQuery($sql);
$amount_due = db_fetch_object($result);

$amount_due = $amount_due - $amount ;
nuRunQuery("UPDATE transaction SET tra_outstanding =$amount_due WHERE tra_customer_id = '".$customer."'");

please help me out to know how to do the casting

Re: SQL CASTING PROBLEM

Posted: Wed Sep 15, 2010 7:21 pm
by steven
at_rcc,
Try this..

Code: Select all

$customer        = $_POST["customer_id"];
$amount          = $_POST["amount_paid"];

$sql             = "SELECT tra_outstanding FROM transaction WHERE tra_customer_id = '$customer'";

$result          = nuRunQuery($sql);                //-- result is a table - even though it might be just 1 row and 1 column

$the_row         = db_fetch_object($result);        //-- $the_row will be the first row

$amount_due      = $the_row->tra_outstanding - $amount ;

nuRunQuery("UPDATE transaction SET tra_outstanding = $amount_due WHERE tra_customer_id = '$customer'");

Also, we have a new video on debugging in nuBuilder, that might help you in the future (video 26)
http://www.nubuilder.com/nubuilderwww/i ... ?nav=video

Hope this helps

Steven