-1

I'm new to JDatabase, and am looking for a little inspiration.

I have a many to many relationship ('table A' 'table J' 'table B') and want to extract data from field in 'A' where field in 'B' = var.

I have written a query and sub query but can't get the where clause working properly.

$option = array(); //prevent problems

$option['driver']   = 'mysql';            
$option['host']     = 'localhost';   // Database host name
$option['user']     = 'xxxxxxxxx';   // User for database authentication
$option['password'] = 'xxxxxxxxx';   // Password for database authentication
$option['database'] = 'xxxxxxxxx';   // Database name

$db = JDatabaseDriver::getInstance( $option );

$subQuery = $db->getQuery(true);
$query    = $db->getQuery(true);

$subQuery->select('parent_id')
  ->from($db->quoteName('tbl_insarea_repeat_relevant_to_function'))
    ->where($db->quoteName('relevant_to_function') . ' = ' . $db->quote('{tbl_work_sheets___vehicle}'));


$query->select('in_area')
    ->from($db->quoteName('tbl_insarea'))
    ->where($db->quoteName('id') . ' IN (' . $subQuery . ')');

  $db->setQuery($query);

try
{
    $result = $db->loadObjectList();
}
catch (RuntimeException $e)
{
    throw new RuntimeException($e->getMessage(), $e->getCode());
}

return $result;
  • 1
    Please post the code you have written so far. – Sharky Dec 21 '18 at 8:16
  • 1
    Please share your code else we don't know where you're going wrong. – Lodder Dec 21 '18 at 9:31
  • @Mono we also need to know what your database tables look like and what result you expect and what your current output is and any errors that you are generating. Pasted code will be formatted properly if each new line starts with at least 4 spaces. To create proper code tabbing visually, use 4, 8, or 12 etc spaces before each line of code in your snippet. – mickmackusa Dec 21 '18 at 21:32
  • @Mono or you can use the Ctrl+K shortcut key after highlighing your snippet. – mickmackusa Dec 21 '18 at 23:15
  • @Mono I hope that you will not abandon this page. We would prefer to help you, because our support can also help researchers. – mickmackusa Dec 23 '18 at 22:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.