I am trying to select data from multiple Jdatabase tables and use a IF-ELSE statement with this :
$db = JFactory::getDbo();
$user = JFactory::getUser();
$query = $db->getQuery(true);
$query->select($db->quoteName('username'))
->from($db->quoteName('#__table1', '#__table2', '#__table3', '#__table4'))
->where($db->quoteName('username') . ' = '. $db->quote($user->username));
$db->setQuery($query);
$result = $db->loadResult();
if($result) {
echo 'hey you are already there';
}
else {
echo 'sorry boss, you are out';
}
HOW IT SHOULD WORK? :
The above query should check whether the username of the current logged-in user is present in any of the four tables ('#__table1', '#__table2', '#__table3', '#__table4')
and should accordingly follow the IF-ELSE STATEMENT
But...
It only selects records from the first table (#__table1)
and it ignores all other tables!
I mean, if the username is already present in (#__table2), (#__table3),(#__table4)
and not in the first table (#__table1)
, it still jumps to ELSE STATEMENT which means it only checks for the username in the first table!?
Any guesses on how to make it select records from all the four tables?