Skip to content

Instantly share code, notes, and snippets.

@AdamMadrzejewski
Last active July 15, 2016 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamMadrzejewski/efa626e744ace977e526 to your computer and use it in GitHub Desktop.
Save AdamMadrzejewski/efa626e744ace977e526 to your computer and use it in GitHub Desktop.
Simple Joomla 3 external script with JSON result from database
<?php
defined('_JEXEC') or die('Restricted access');
define('DS', DIRECTORY_SEPARATOR);
// Use these variables for direct file access
// define('_JEXEC', 1);
// define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once (JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once (JPATH_BASE.DS.'includes'.DS.'framework.php');
$app = JFactory::getApplication('site');
$db = JFactory::getDbo();
$jinput = JFactory::getApplication()->input;
$region = $jinput->get('region', 'Abruzzo', 'STRING');
$query = $db->getQuery(true);
$query
->select($db->qn('id'))
->from($db->qn('#__ambulatori_regioni'))
->where($db->qn('nome').' = '.$db->q($region));
$db->setQuery($query);
$result = $db->loadResult();
echo json_encode($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment