This topic is locked

DAL update returning "0" in Int Field

12/24/2011 5:40:37 AM
PHPRunner General questions
buddy author

Happy Holiday's all. Great forum.
I am trying to add records to a table (MASH_Merge) with values from MASH_Company and MASH_Contacts. All works well except the values from MASH_Company (Sales USD (mil),Employees) goes into the destination table as "0" rather than the actual numeric value. All fields are set a INT.
Here is the code being used from a button:
global $conn,$dal;

$rs = CustomQuery("SELECT ID,First Name,Last Name
FROM
MASH_Contacts",$conn);

$rs_company = CustomQuery("SELECT
Sales USD (mil),Employees FROM MASH_Company WHERECompany`='Company Name' LIMIT 1",$conn);

$record_company = db_fetch_array($rs_company);
//copy each record in the source table in the MASH_Merge using DAL (Data Access Layer)

$tblEvents = $dal->Table("MASH_Merge");

$total_records = 0;

while($record = db_fetch_array($rs))

{

//$tblEvents->Value["ID"]=$record['ID'];

$tblEvents->Value["First Name"]=$record['First Name'];

$tblEvents->Value["Last Name"]=$record['Last Name'];

$tblEvents->Value["Sales USD (mil)"] = $record_company['Sales USD (mil)'];//get this value from the MASH_Company

$tblEvents->Value["Employees"] = $record_company['Employees'];//get this value from the MASH_Company
$tblEvents->Add();

$total_records++;

}
Hope you can help.
Buddy

C
cgphp 12/24/2011

Try to print the $record_company array before the dal statement and check the server response in firebug:

global $conn,$dal;

$rs = CustomQuery("SELECT ID,First Name`,`Last Name`

FROM

MASH_Contacts",$conn);
$rs_company = CustomQuery("SELECT `Sales USD (mil)`,Employees FROM MASH_Company WHERE `Company`='Company Name' LIMIT 1",$conn);

$record_company = db_fetch_array($rs_company);
print_r($record_company); //-------> print the $record_company array <-----------

exit();
//copy each record in the source table in the MASH_Merge using DAL (Data Access Layer)

$tblEvents = $dal->Table("MASH_Merge");

$total_records = 0;

while($record = db_fetch_array($rs))

{

//$tblEvents->Value["ID"]=$record['ID'];

$tblEvents->Value["First Name"]=$record['First Name'];

$tblEvents->Value["Last Name"]=$record['Last Name'];

$tblEvents->Value["Sales USD (mil)"] = $record_company['Sales USD (mil)'];//get this value from the MASH_Company

$tblEvents->Value["Employees"] = $record_company['Employees'];//get this value from the MASH_Company
$tblEvents->Add();

$total_records++;

}
buddy author 12/24/2011



Try to print the $record_company array before the dal statement and check the server response in firebug:

global $conn,$dal;

$rs = CustomQuery("SELECT ID,First Name`,`Last Name`

FROM

MASH_Contacts",$conn);
$rs_company = CustomQuery("SELECT `Sales USD (mil)`,Employees FROM MASH_Company WHERE `Company`='Company Name' LIMIT 1",$conn);

$record_company = db_fetch_array($rs_company);
print_r($record_company); //-------> print the $record_company array <-----------

exit();
//copy each record in the source table in the MASH_Merge using DAL (Data Access Layer)

$tblEvents = $dal->Table("MASH_Merge");

$total_records = 0;

while($record = db_fetch_array($rs))

{

//$tblEvents->Value["ID"]=$record['ID'];

$tblEvents->Value["First Name"]=$record['First Name'];

$tblEvents->Value["Last Name"]=$record['Last Name'];

$tblEvents->Value["Sales USD (mil)"] = $record_company['Sales USD (mil)'];//get this value from the MASH_Company

$tblEvents->Value["Employees"] = $record_company['Employees'];//get this value from the MASH_Company
$tblEvents->Add();

$total_records++;

}



Thank Cristian. I added that and was not able to get a server response from firebug. It may be a bit over my head.
I do see that the dal statement includes while($record = db_fetch_array($rs)) which does transfer the right information
but does not have a call to ($record = db_fetch_array($rs_company)) which contains the information I am missing.

C
cgphp 12/24/2011

You don't need a while loop over the $record_company = db_fetch_array($rs_company) because the $rs_company query returns only one record.

buddy author 12/24/2011



You don't need a while loop over the $record_company = db_fetch_array($rs_company) because the $rs_company query returns only one record.


Sent you email Cristian.