Problema con Query

freddie1978

New Member
Buongiorno, devo eseguire una query su un campo calc ma ricevo http error 500.
La query deve restituirmi la somma di un determinato campo numerico di una tabella.
Sapete dirmi dove sbaglio ? Grazie.

$row_ordine='{fatture___ordine}';
$x='{fatture___importo_totale_ordine}';
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query->select('sum('.$db->quoteName('importo_fattura').')');
$query->as($db->quoteName('temp'));
$query->from($db->quoteName('fatture'));
$query->WHERE($db->quoteName('ordini')=$row_ordine);
$db->setQuery($query);
$results = $db->loadResult();
return $results;
$rimanente=$x-$result;
return $rimanente;
 
A couple of things... try this and see comments inserted here:
Code:
$row_ordine = '{fatture___ordine}';
$x = '{fatture___importo_totale_ordine}';
$db = JFactory::getDbo(); // you had FabrikWorker, I'm just using Joomla's default here
$query = $db->getQuery(true);
$query->select('sum('.$db->quoteName('importo_fattura').')');
// dropped the "as" line
$query->from($db->quoteName('fatture'));
$query->where($db->quoteName('ordini').' = '.$db->quote($row_ordine)); // fixed syntax error and added $db->quote just in case
$db->setQuery($query);
$results = $db->loadResult();
return $results; // this will return the sum... but what's the next bit for?
$rimanente = $x - $result; // $result is not defined... you had only plural ($results) before
return $rimanente; // you have returned something already above

And thanks for posting in English :rolleyes:
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top