Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

SQL CASTING PROBLEM

Post Reply
at_rcc
Posts: 32
Joined: Thu Sep 02, 2010 11:19 am

SQL CASTING PROBLEM

Unread post 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
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: SQL CASTING PROBLEM

Unread post 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
A short post is a good post.
Post Reply