SQL query only returning array not value

Hi,

I am trying to update a field with the latest number from the database with a before_save logic hook.
However nothing happens! After experimenting it seems it might be something to do with it returning an array and not just the number.
I just want to get the latest number (invoicenumbergeneration_c) as a specific number.

$sqlno = “select * from aos_invoices_cstm order by invoicenumbergeneration_c desc limit 0, 1 ;”;
$queryno = $db->query($sqlno, true,"Error reading tasks entry: ");
$resultno = $db->fetchByAssoc($queryno);
$numberno = $resultno[invoicenumbergeneration_c];
$bean->resolution = $numberno;

Any ideas?

You are using fetchByAssoc which returns an array. If you are expecting as single result you can use getOne($queryno)

Take a look at this : http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.7/02_Application_Framework/Helper_Classes/DBManagerFactory/

1 Like

Thanks, worked perfectly!