SQL WHERE clause with a variable (current article ID)

by Wil-It   Last Updated March 05, 2018 19:10 PM

I am trying to do a simple calculation on two Joomla custom fields in a module. I get the article ID as a variable and want to put this in the WHERE clause to get the right custom field value. Have tried many thing, but can't manage. The field_id is 4 of the field I need and when I fill in the article ID as a number, it is working, but I can't get the variable to work (which I need so the module uses the article ID). Hope somebody can help me out?

$article_id = JFactory::getApplication()->input->get('id');

   $db = JFactory::getDbo();
   $query = $db->getQuery(true);
   $query->select('value', 'item_id', 'field_id')
         ->from ($db->quoteName('#__fields_values'))

     $result = $db->loadResult();
     return $result;


Related Questions

PHP7.2 Undefined variable: option in .... index.php

Updated January 24, 2019 16:10 PM

SET variables in JDatabaseQuery

Updated February 04, 2018 14:10 PM

Pass var to jQuery script

Updated June 26, 2015 12:20 PM

Get the menu item variable using Jinput

Updated March 27, 2015 05:03 AM