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'))
         ->where($db->quoteName('#__fields_values.field_id=4'))
         ->where($db->quoteName('#__fields_values.item_id')=$article_id);
   $db->setQuery($query);


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

Thanks!



Related Questions


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

Params in Custom Component List View

Updated August 08, 2017 00:10 AM